python创建函数模块_Python 创建和发布安装函数模块

1. create dir "nester" under C:\Users\eric\AppData\Local\Programs\Python\Python35-32\

2. create a nester.py under C:\Users\eric\AppData\Local\Programs\Python\Python35-32\nester\

"""this is a new fuction, which work for a list"""

def print_lol(the_list):

""" one arguement is the_list"""

for each_item in the_list:

if isinstance(each_item,list):

print_lol(each_item)

else:

print(each_item)

3. Run F5, Python解析器重置,加载了新的函数

RESTART: C:\Users\eric\AppData\Local\Programs\Python\Python35-32\nester\nester.py

>>> movies = ["abc","ehll","asdfdsf"]

>>> print_lol(movies)

abc

ehll

asdfdsf

>>>

4. create setup.py  under C:\Users\eric\AppData\Local\Programs\Python\Python35-32\nester\

from distutils.core import setup

setup(

name = 'nester',

version = '1.0.0',

py_modules = ['nester'],

author = 'eric',

author_email= 'eric@126.com',

url = 'http://126.com',

description = 'a simple nested lists',

)

5. create distribution under CMD or Shell

C:\Users\eric\AppData\Local\Programs\Python\Python35-32\nester>c:\Users\eric\AppData\Local\Programs\Python\Python35-32\python.exe setup.py sdist

running sdist

running check

warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)

warning: sdist: standard file not found: should have one of README, README.txt

writing manifest file 'MANIFEST'

creating nester-1.0.0

making hard links in nester-1.0.0...

hard linking nester.py -> nester-1.0.0

hard linking setup.py -> nester-1.0.0

creating dist

creating 'dist\nester-1.0.0.zip' and adding 'nester-1.0.0' to it

adding 'nester-1.0.0\nester.py'

adding 'nester-1.0.0\PKG-INFO'

adding 'nester-1.0.0\setup.py'

removing 'nester-1.0.0' (and everything under it)

6. install nester moudle to your local

C:\Users\eric\AppData\Local\Programs\Python\Python35-32\nester>c:\Users\eric\AppData\Local\Programs\Python\Python35-32\python.exe setup.py install

running install

running build

running build_py

creating build

creating build\lib

copying nester.py -> build\lib

running install_lib

copying build\lib\nester.py -> c:\Users\eric\AppData\Local\Programs\Python\Python35-32\Lib\site-packages

byte-compiling c:\Users\eric\AppData\Local\Programs\Python\Python35-32\Lib\site-packages\nester.py to nester.cpython-35.pyc

running install_egg_info

Writing c:\Users\eric\AppData\Local\Programs\Python\Python35-32\Lib\site-packages\nester-1.0.0-py3.5.egg-info

7. import and test new moudle

>>> import nester

>>> cast = ['palin','cleese','book','jones']

>>> print_lol(cast)

Traceback (most recent call last):

File "", line 1, in

print_lol(cast)

NameError: name 'print_lol' is not defined

>>> nester.print_lol(cast)

palin

cleese

book

jones

>>>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值