Python Module-sys module

Source: Internet
Author: User
Tags readline stdin

Sys.version get version information for Python interpreter

>>> sys.version ' 2.7.12 (default, Dec  4, 14:50:18) \N[GCC 5.4.0 20160609] '

Sys.platform returns the operating system platform name

>>> sys.platform ' linux2 '

Sys.getrecursionlimit () #获取最大递归层数

>>> Sys.getrecursionlimit () 1000

Sys.setrecursionlimit () #设置最大递归层数

>>> sys.setrecursionlimit () >>> sys.getrecursionlimit () 5000

Sys.getdefaultencoding () #获取解释器默认编码

>>> sys.getdefaultencoding () ' ASCII '

Sys.getfilesystemencoding () #获取内存数据存到文件里的默认编码

>>> sys.getfilesystemencoding () ' UTF-8 '

Sys.maxint the largest int value

>>> sys.maxint9223372036854775807

Sys.maxsize in Python3

>>> sys.maxsize9223372036854775807

Sys.path returns the search path for the module, using the value of the PYTHONPATH environment variable when initializing

>>> sys.path[', '/usr/lib/python35.zip ', '/usr/lib/python3.5 ', '/usr/lib/python3.5/plat-x86_64-linux-gnu ', '/usr/lib/python3.5/lib-dynload ', '/home/sch01ar/.local/lib/python3.5/site-packages ', '/usr/local/lib/ Python3.5/dist-packages ', '/usr/lib/python3/dist-packages ']

SYS.ARGV command-line argument list, the first element is the path of the program itself

Import sysif sys.argv:   print (SYS.ARGV)

Run results

Sys.exit (n) exit program, Exit normally (0)

Import sysprint (' sys test ') sys.exit (0) print (' a ')

Run results

Sys.exit () adds a parameter to print before exiting the program

Import sysprint (' sys test ') sys.exit (' Python would exit ')

Run results

Sys.exit () for exiting in the main thread, Os._exit () for exiting in thread

Sys.stdin.readline () standard input

>>> sys.stdin.readline () python ' python\n '

Sys.stdout.write () Standard output

Import syssys.stdout.write (' python\n ')

Run results

Python Module-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.