Python module specification

Source: Internet
Author: User

1 #/usr/bin/python2 #-*-coding=utf-8-*-3 4 """This was a standard module"""5 6 ImportSYS7 8 __author__='Wang'9 Ten  One defTest (): Aargs =sys.argv () -     ifLen (args) = = 1: -         Print('Hello world!') the     elifLen (args) = = 2: -         Print('Hello%s!'% args[1]) -     Else: -         Print('Too many arguments!') +  -  + if __name__=='__main__': ATest ()

1, the first line of code under the Linux and Mac systems, the script can be run directly.

2. The second line of code specifies that the file uses the standard Utf-8 standard.

3, the fourth line of code document gaze, the first string of any module code is treated as a document comment of the module.

4. The sixth line of code imports the SYS module.

5. The eighth line of code uses __author__ variables to write the author in.

6, the 21st line of code, when we run the module file on the command line, the Python interpreter set a special variable __name__ __main__ , and if the module is imported elsewhere, the if judgment will fail, so this if Testing allows a module to execute some extra code when it runs through the command line, most commonly by running tests.

7, in a module, we may define a lot of functions and variables, but some functions and variables we want to use for others, some functions and variables we want to use only within the module. In Python, this is done by a _ prefix.

Python module specification

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.