Common methods for the Python sys module __python

Source: Internet
Author: User

The SYS module includes a set of very useful services that contain a number of function methods and variables to handle the Python run-time configuration and resources to interact with the system environment outside of the previous program, such as the Python interpreter.

1. Import SYS module

First, open the terminal emulator into the Python interpreter or open the IDE editor to create a new. py suffix name of the Python program file.

Here is an example of an action in an interpreter:

>>> Import SYS #导入sys模块
>>> dir (SYS) #dir () method to view the methods available in the module

Note: If you are in the editor, be sure to notice the code in advance, otherwise Chinese will be garbled.


2. SYS module IMPORTANT function variable

1) Sys.stdin standard input stream.
2) sys.stdout standard output stream.
3) Sys.stderr standard error stream.
4) Sys.path The list of directory names for the directory where the module resides.
5 sys.argv the command line parameters, including the script name.
6) Sys.platform return to the current system platform, such as: Win32, Linux and so on.


3. Sys Common method usage instruction

The Sys.exit method can exit the current program and provide an integer type, usually using the 0 function as the parameter of this method,
Of course, you can also use string parameters to indicate error information that is not successful.

The Sys.modules method can map the name of a module to a real-world module, and it applies only to the currently imported module.

There are 3 module variables: Sys.stdin, sys.stdout, Sys.stderr They are class file (File-like) stream objects.


Source: http://www.iplaypython.com/module/sys.html

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.