- 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
- 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 theos.path
module, and if you want to read all the lines in all the files on the command line see thefileinput
module. For creating temporary files and directories see thetempfile
module, and for high-level file and directory handling see theshutil
module. 参见:https://docs.python.org/3/library/os.html
In layman's terms:
- sys is used to utilize some variables or functions of the Python compiler to accomplish tasks.
- os is used to make use of some variables and functions of the operating system (mostly renamed to improve portability) for this purpose.