Python-shared module code

Source: Internet
Author: User

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:

 

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.