Python Basic 7.6 sys module

Source: Internet
Author: User
Tags stdin

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

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.