1. create dir "nester" under C:UsersericAppDataLocalProgramsPythonPython35-32
2. create a nester.py under C:UsersericAppDataLocalProgramsPythonPython35-32 ester
"""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:UsersericAppDataLocalProgramsPythonPython35-32 ester ester.py >>> movies = ["abc","ehll","asdfdsf"] >>> print_lol(movies) abc ehll asdfdsf >>>
4. create setup.py under C:UsersericAppDataLocalProgramsPythonPython35-32 ester
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:UsersericAppDataLocalProgramsPythonPython35-32 ester>c:UsersericAppDataLocalProgramsPythonPython35-32python.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 ester-1.0.0.zip' and adding 'nester-1.0.0' to it adding 'nester-1.0.0 ester.py' adding 'nester-1.0.0PKG-INFO' adding 'nester-1.0.0setup.py' removing 'nester-1.0.0' (and everything under it)
6. install nester moudle to your local
C:UsersericAppDataLocalProgramsPythonPython35-32 ester>c:UsersericAppDataLocalProgramsPythonPython35-32python.exe setup.py install running install running build running build_py creating build creating buildlib copying nester.py -> buildlib running install_lib copying buildlib ester.py -> c:UsersericAppDataLocalProgramsPythonPython35-32Libsite-packages byte-compiling c:UsersericAppDataLocalProgramsPythonPython35-32Libsite-packages ester.py to nester.cpython-35.pyc running install_egg_info Writing c:UsersericAppDataLocalProgramsPythonPython35-32Libsite-packages ester-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 "<pyshell#3>", line 1, in <module> print_lol(cast) NameError: name 'print_lol' is not defined >>> nester.print_lol(cast) palin cleese book jones >>>