Difference between sys and os modules in Python

  1. sys: This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available. 参见:https://docs.python.org/3/library/sys.html
  2. os:This module provides a portable way of using operating system dependent functionality. If you just want to read or write a file see open(), if you want to manipulate paths, see the os.path module, and if you want to read all the lines in all the files on the command line see the fileinput module. For creating temporary files and directories see the tempfile module, and for high-level file and directory handling see the shutil module. 参见:https://docs.python.org/3/library/os.html

In layman's terms:

  1. sys is used to utilize some variables or functions of the Python compiler to accomplish tasks.
  2. os is used to make use of some variables and functions of the operating system (mostly renamed to improve portability) for this purpose.

Guess you like

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