Python's OS module and SYS module

Source: Internet
Author: User

The main usage of the Python OS module

The OS modules in Python can be used to write platform-independent file system operations.

The main methods are as follows:
Some tag attributes
A string that splits a row in a os.linesep file
Os.sep File path name delimiter
Os.curdir the string name of the current working directory
Os.pardir Parent Directory String name
Common methods
Os.remove () deleting files
Os.rename () Renaming files
Os.walk () Generate all file names under the directory tree
Os.chdir () Change Directory
Os.mkdir/makedirs Creating a directory/multi-level directory
Os.rmdir/removedirs Deleting a directory/multi-level directory
Os.listdir () lists files for the specified directory
OS.GETCWD () Get the current working directory
Os.chmod () Changing directory permissions
Os.path.basename () Remove directory path, return file name
Os.path.dirname () Remove file name, return directory path
Os.path.join () combines parts of the separation into one path name
Os.path.split () return (DirName (), basename ()) tuple
Os.path.splitext () (returned filename,extension) tuple
Os.path.getatime\ctime\mtime returns the last access, creation, modification time, respectively
Os.path.getsize () returns the file size
Os.path.exists () is present
Os.path.isabs () is an absolute path
Os.path.isdir () is a directory
Os.path.isfile () is a file

SYS.ARGV command line argument list, the first element is the path of the program itself
Sys.modules.keys () returns the list of all modules that have been imported
Sys.exc_info () Gets the exception class currently being processed, Exc_type, Exc_value, exc_traceback the exception details currently handled
Sys.exit (n) exit program, Exit normally (0)
Sys.hexversion gets the version value of the Python interpreter, 16 binary format such as: 0x020403f0
Sys.version get version information for Python interpreter
Sys.maxint the largest int value
Sys.maxunicode the largest Unicode value
Sys.modules returns the module field of the system import, key is the module name, value is the module
Sys.path returns the search path for the module, using the value of the PYTHONPATH environment variable when initializing
Sys.platform returns the operating system platform name
Sys.stdout Standard Output
Sys.stdin Standard input
Sys.stderr Error Output
Sys.exc_clear () to clear current or recent error messages that are present on the current thread
Sys.exec_prefix returns the location of the platform standalone Python file installation
Sys.byteorder The local byte rule indicator, the value of the Big-endian platform is ' big ', the value of the Little-endian platform is ' little '
Sys.copyright record python copyright-related things
API version of C for the Sys.api_version interpreter
Sys.version_info
>>> Sys.version_info
(2, 4, 3, ' final ', 0) ' final ' means final, also ' candidate ' indicates a candidate, indicating the version level, whether there is a subsequent release
Sys.displayhook (value) if value is not NULL, the function will output it to sys.stdout and save him in __builtin__._. In Python's interactive interpreter, ' _ ' represents the result of the last input you entered, Hook is the meaning of the hook, the last results hooked
Sys.getdefaultencoding () returns the default character encoding format you are currently using
Sys.getfilesystemencoding () Returns the encoded name of the Unicode file name converted to the system file name
Sys.setdefaultencoding (name) is used to set the current default character encoding, if name and any one of the available encodings do not match, throw lookuperror, this function will only be used by the site module Sitecustomize, Once the site module is used, he will remove it from the SYS module.
Sys.builtin_module_names List of modules imported by the Python interpreter
Sys.executable Python interpreter path
Sys.getwindowsversion () Get the version of Windows
Sys.stdin.readline () reads a line from the standard input, Sys.stdout.write ("a") screen output a

Python's OS module and SYS module

Related Article

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.