sys module of python

First sort out the difference between OS module and SYS module

  • The official explanation of the os and sys modules is as follows:
  • os: This module provides a portable way of using operating system dependent functionality.
  • This module provides a convenient way to use operating system functions.
  • sys: This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter.
  • This module provides access to variables used or maintained by the interpreter and functions that interact with the interpreter.

Summary: The os module is responsible for the interaction between the program and the operating system, and provides an interface to access the bottom layer of the operating system; the sys module is responsible for the interaction between the program and the python interpreter, and provides a series of functions and variables for manipulating the python runtime environment.

sys common methods:

sys.argv # command line parameter list, the first element is the path of the program itself.
import random
import sys
# print(sys.modules.keys()) # Returns a list of all imported modules
#dict_keys(['builtins', 'sys', '_frozen_importlib', '_imp', '_warnings', '_thread', '_weakref', '_frozen_importlib_external', '_io', 'marshal', 
'nt', 'winreg', 'zipimport', 'encodings', 'codecs', '_codecs', 'encodings.aliases', 'encodings.utf_8', '_signal', '__main__', 'encodings.latin_1',
'io', 'abc', '_weakrefset', 'site', 'os', 'errno', 'stat', '_stat', 'ntpath', 'genericpath', 'os.path', '_collections_abc', '_sitebuiltins',
'sysconfig', 'random', 'warnings', 'types', 'functools', '_functools', 'collections', 'operator', '_operator', 'keyword', 'heapq', '_heapq',
'itertools', 'reprlib', '_collections', 'weakref', 'collections.abc', 'math', 'hashlib', '_hashlib', '_blake2', '_sha3', 'bisect', '_bisect', '_random']) # print(sys.exit(status)) Exit the program, you can set the return value or content print(sys.version) # version number of python interpreter print(sys.platform) # Returns the operating system platform name sys.stdout # stdout sys.stdin # standard input sys.stderr # error output sys.path # Returns the search path of the module, using the value of the python path environment variable during initialization

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325842179&siteId=291194637