Common modules in Python (SYS module)

Source: Internet
Author: User
Tags stdin

First, import SYS module operation

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

Here is an example of an action in the interpreter:

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

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

Second, SYS module important function variables

1), Sys.stdin standard input stream.
2), sys.stdout standard output stream.
3), Sys.stderr standard error stream.
4), the directory Name list of the directory where the Sys.path lookup module is located.
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.

Third, the use of the Sys method of instruction

Sys.exit method can exit the current program, can provide an integer type, usually we use 0 to represent the function, as the parameter of this method,
Of course, you can also use a string parameter, indicating the error message is unsuccessful.

The Sys.modules method maps the name of the module to a module that is actually present and applies only to modules that are currently imported.

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

Four, sys module case code demo

Above is the demo code for the Python sys module, and the gray part below is the output.

Five, sys module Tutorial Summary:

All the tutorials of the snake Network Python source code is in the Linux Ubuntu System test run, you can also self-debugging, improve their hands-on problem-solving ability.

SYS and OS modules are often used in our daily operating system editing, which is a must-know knowledge, we should practice more.

Play Snake net article, reprint please indicate the source and article URL: http://www.iplaypy.com/module/sys.html

Common modules in Python (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.