python-Sharing Module Code

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.