Analysis of Python OS and sys modules, pythonossys Module

Source: Internet
Author: User

Analysis of Python OS and sys modules, pythonossys 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 the variables used or maintained by the interpreter and the functions that interact with the interpreter.

Common OS Methods

OS. remove () delete a file

OS. rename () rename the file

OS. walk () generates all file names under the directory tree

OS. chdir () Change directory

OS. mkdir/makedirs create directory/multi-level directory

OS. rmdir/removedirs Delete directory/multi-level directory

OS. listdir (): List objects in a specified directory

OS. getcwd () to get the current working directory

OS. chmod () change Directory Permissions

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 () combines 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 return the last access, creation, and modification time respectively.

OS. path. getsize () returns the file size.

OS. path. exists ()

Whether OS. path. isabs () is an absolute path

Whether OS. path. isdir () is a directory

Whether OS. path. isfile () is a file

Common sys Methods

Sys. argv command line parameter List. The first element is the program path.

Sys. modules. keys () returns the list of all imported modules.

Sys. exc_info () obtains the exception classes currently being processed, including exc_type, exc_value, and exc_traceback.

Sys. exit (n) exit the program. exit (0) when the program Exits normally)

Sys. hexversion: get the version value of the Python interpreter. The hexadecimal format is 0x020403F0.

Sys. version: get the version information of the Python interpreter.

Maximum Int value of sys. maxint

Maximum Unicode value of sys. maxunicode

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 search path of the module. The value of the PYTHONPATH environment variable is used during initialization.

Sys. platform: returns the name of the operating system platform.

Sys. stdout standard output

Sys. stdin standard input

Sys. stderr error output

Sys. exc_clear () is used to clear the current or recent error message of the current thread.

Sys.exe c_prefix: return the location where the python file on the platform is installed.

Sys. byteorder indicates the 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 records the copyright related to python

API version of sys. api_version C of the interpreter

Summary

The OS module is responsible for the interaction between the program and the operating system, and provides the interface for accessing the underlying 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, it is used to manipulate the runtime environment of python.

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.