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