Overview: share a function module that defines an output multi-list element.
1. First create a folder for the template
Edit the nester.py file with the following content:
def print_lol(the_list): forin 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
fromimport setupsetup( ‘nester‘, ‘1.0.0‘, py_moudles = [‘nester‘], ‘csuldw‘, ‘[email protected]‘, ‘http://www.csuldw.com‘, ‘A simple printer of nested lists‘,)
Now you have a folder that contains two files: the template code is placed in nester.py, and the metadata about the template is placed in the setup.py. Now to build your release.
3. Build a publishing file
Running on CentOS
python2 setup.py sdist
The following information will appear
4. Install the publication to your local python copy
Terminal execution:
The release is ready
Pre-installation folder Nester only nester.py and setup.py two files, after installation: Dist MANIFEST nester.py nester.pyc setup.py four files.
5. Testing
In Terminal input:
import nesterlists=[["xuxu",1991,"huanhua","hunau"],"ldw","csu"]print_lol(lists)
The third line error occurs because the Python template implements the namespace, which is used as an identifier
The correct command to invoke Print_lol should be:
nester.print_lol(lists)
Results:
Reference: "Head first Python" Barry.
python-Sharing Module Code