Differences between OS and sys modules and their common methods. Summary of ossys Module
Official explanation:
OS: This module provides a portable way of using operating system dependent functionality.
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.
Translation: provides access to variables used or maintained by the interpreter and functions used in interaction with the interpreter.
Common OS methods are summarized as follows:
OS. remove () # delete a file OS. rename () # rename the file OS. walk () # generate all file names under the directory tree OS. chdir () # change the directory OS. mkdir/makedirs () # create a directory/multi-level directory OS. rmdir/removedirs # Delete directory/multi-level directory OS. listdir () # list the file OS in the specified directory. getcwd () # Get the current working directory OS. chmod () # change the directory permission OS. path. basename () # Remove the directory path and return the file name OS. path. dirname () # Remove the file name and return the directory path OS. path. join () # combine the separated parts into a path name OS. path. split () # returns the (dirname (), basename () tuples OS. path. splitext () # returns the filename, extension) tuples OS. path. getatime \ ctime \ mtime # returns the last access, creation, and modification time OS respectively. path. getsize () # returns the file size OS. path. exists () # Whether OS exists. path. isabs () # whether it is an absolute path OS. path. isdir () # whether it is a directory OS. path. isfile () # whether it is a file
The common methods of sys are summarized as follows:
Sys. argv # List of command line parameters. The first element is the program path sys. modules. keys () # Return the list of all imported modules sys. exc_info () # obtain the exception classes currently being processed, including exc_type, exc_value, and exc_traceback. exit (n) # program. exit (0) sys when the program Exits normally. hexversion # obtain the version value of the Python interpreter. The hexadecimal format is 0x020403F0 sys. version # obtain the version information of the Python interpreter sys. maxint # The maximum Int value sys. maxunicode # maximum Unicode value sys. modules # Return the module field imported by the system. The key is the module name and the value is the module sys. path # Return the module's search path. during initialization, use the PYTHONPATH environment variable value sys. platform # Return OS platform name sys. stdout # standard output sys. stdin # standard input sys. stderr # incorrect output sys. exc_clear () # used to clear the current or recent error message of the current thread sys.exe c_prefix # Return the location where the platform-independent python file is installed sys. byteorder # indicator of the local byte rule. The value of the big-endian platform is 'Big ', and that of the little-endian Platform Is 'Little 'sys. copyright # record python copyright related things sys. api_version # API version sys of interpreter C. version_info # obtain the Python interpreter version information sys. getwindowsversion # obtain the Windows version sys. getdefaultencoding # Return the current default character encoding format sys. getfilesystemencoding # returns the encoded name sys that converts the Unicode file name to the system file name. setdefaultencoding (name) # used to set the current default character encoding sys. builtin_module_names # list of modules imported by the Python interpreter sys.exe cutable # Python interpreter path sys. stdin. readline # Read a row from standard input, sys. stdout. write ("a") screen output