Python-shared module code
Overview:Share a function module that defines multiple list elements.
1. Create a folder for the Template
Edit the nester. py file with the following content:
def print_lol(the_list): for each_item in the_list: if isinstance(each_item,list): print_lol(each_item) else: print(each_item)
2. Create a file named "setup. py" in the new folder.
The source code is as follows:
from distutils.core import setupsetup( name = 'nester', version = '1.0.0', py_moudles = ['nester'], author = 'csuldw', author_email = 'csu.ldw@csu.edu.cn', url = 'http://www.csuldw.com', description = 'A simple printer of nested lists',)
Now there is a folder that contains two files: The template code is put in nester. py, and the metadata of the template is put in setup. py. Build your release now.
3. Build a publishing File
Run on centos
python2 setup.py sdist
The following information appears:
4. Install the release to your local python copy.
Terminal execution:
python2 setup.py install
Release ready
Before installation, the folder nester contains only the nester. py and setup. py files. After installation, there are four files: dist MANIFEST nester. py nester. pyc setup. py.
5. Test
Enter at the terminal:
import nesterlists=[[xuxu,1991,huanhua,hunau],ldw,csu]print_lol(lists)
At this time, the third row reports an error because the python template implements the namespace, which is used as the identifier
The correct command to call print_lol should be:
nester.print_lol(lists)
Result: