python笔记2--函数模块的封装,发布,使用,在pypi的发布以及更新
一.函数模块化:
1.注释:描述模块,描述函数
【nester.py】
"""This is the "nester.py" module and it provides one function called print_lol() which prints lists that may or may not include nested lists.""" def print_lol(the_list): """This function takes one positional argument called "the_list", which is any Python list (of - possibly - nested lists). Each data item in the provided list is (recursively) printed to the screen on it’s own line.""" for each_item in the_list: if isinstance(each_item, list): print_lol(each_item) else: print(each_item)
2.函数存放地址:首先要知道python会在哪些地方搜索模块,
import sys sys.path
二.准备发布
1.为模块创建文件夹nester,里面包含文件nester.py;
2.新建setup.py文件,增加一些setup信息
from distutils.core import setup setup( '''此处参数名不能修改,后面数据可以不一样''' name='nester', version='1.0.0', py_modules=['nester'], author='hfpython', author_email='alexkn14@gmail.com' url='', description='', )
3.构建发布(在文件夹中打开编辑窗口执行以下命令)
python3 setup.py sdist
sudo python3 setup.py install
操作结束后,可以看到模块nester文件夹里包含文件夹build--》lib文件夹,dist文件夹,文件:manifest,nester.py,nester.pyc,setup.py.
此时,模块已经加载到python shell中,可以直接引用。
三.模块的引用
import nester
四.在pypi上上传代码
1.在pypi上注册
2.向pypi上传代码
python3 setup.py register
输入在pypi上的相关信息,完成二次注册后,执行命令上传代码
python3 setup.py sdist upload
五.更新--用参数为不同的选择定制API
1.修改setup.py的version
2.上传本地修改代码:
python3 setup.py sdist upload

浙公网安备 33010602011771号