A. SYS moduleSYS module main function is to get the parameters[email protected] pythonscripts]# cat 2.py#!/usr/bin/python#coding =utf-8Import OSImport SYSif __name__ = = ' __main__ ':print (' sys.argv[0]= {0} '. Format (sys.argv[0]))print (' sys.argv[1]= {0} '. Format (sys.argv[1]))print (' sys.argv[2]= {0} '. Format (sys.argv[2]))Operation Result:[[email protected] pythonscripts]# python 2.py 1 1.txtsys.argv[0]= 2.pysys.argv[1]= 1sys.argv[2]= 1.txt#2. Sys.stdint Sys.stdin Sys.stderr provides better control of input and output (line wrapping). StdOut, etc. is not wrapped by default. print ' AA '*2 sys.stdout.write (' Hello Liuzhengkun ') Print (' Hello World ') >>>AAAAHello Liuzhengkun Hello worldprint ' # # # #sys. stdin line Break # # #让 Sys.stdout sys.stdin sys.err The default line break, you need to add a newline character. print ' AA '*2 sys.stdout.write (' Hello Liuzhengkun \ n') Print (' Hello World ') >>># # # #sys. stdin line Break # # #AAAAHello LiuzhengkunHello World#3. Redirect to a file from the console. Generate a new 1.log under the current file with the contents of the file Hellof = open(' 1.log ',' W ') sys.stdout = fprint ' Hello ' #4. Sys.exit (n) Exit: Function: Executes to the end of the main program, the interpreter exits automatically. 0 is normal exit, not 0 number of abnormal exit
Python Basic 7.6 sys module