Python built-in modules

Source: Internet
Author: User
Tags stdin

Python built-in module [Sys,os,os.path,stat]

Built-in modules are Python-enabled, and when using built-in modules, you need to follow the first import in use

First, SYS
Object Describe
sys.argv Command-line arguments get, return type is list, first element is the path of the program itself
Sys.path Returns a list of the search paths for the module, the first element is the directory of the current program, and the value of the PYTHONPATH environment variable when it is initialized
Sys.modules.keys () Returns the list of all modules that have been imported
Sys.modules Returns all imported module dictionaries, key module names, and value is the module path
Sys.exc_info () Gets the exception class currently being processed, exc_type,exc_value,exc_traceback the exception details currently being processed
Sys.exc_clear () Used to clear current or recent error messages that are present on the current thread
Sys.exec_prefix Returns the location of the Python file installation
Sys.exit (N) Exit the program, exit normally (0)
Sys.hexversion Gets the version value of the Python interpreter, 16 binary format such as: 0x020103f0
Sys.version Get version information for Python interpreter
Sys.displayhook (value) If value is not NULL, the function will output it to sys.stdout (use the Reference document in detail)
Sys.excepthook Abnormal backtracking correlation
Sys.stdin Standard input
Sys.stdin.read () Enter a row
Sys.stdin.readline () Read a line from standard input, Sys.stdout.write ("a") screen output a
Sys.stdout Standard output
Sys.stdout.write (' AAA ') Standard output content
Sys.stdout.writelines () No Line break output
Sys.stderr Error related
Sys.pathform Returns the operating system platform name
Sys.byteorder Indicator of the local byte rule, 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
Sys.api_version API version of the interpreter C
Sys.version_info ' final ' means final, also ' candidate ' indicates a candidate, indicating the version level, whether there is a subsequent release
Sys.getdefaultencoding () Returns the default character encoding format that you are currently using
Sys.getfilesystemencoding () Returns the encoded name of the Unicode file name converted to the system file name
Sys.builtin_module_names List of built-in modules imported by the Python interpreter
Sys.executable Python interpreter path
Sys.getwindowsversion () Get the version of Windows

Second, OS module

Object Describe
Os.remove () deleting files
Os.unlink () deleting files
Os.rename () Renaming files
Os.listdir () List all files in the specified directory
Os.curdir 返回当前目录: (‘.‘)
Os.pardir 获取当前目录的父目录字符串名:(‘..‘)
Os.chdir () Change the current working directory
OS.GETCWD () Get the current file path
Os.mkdir () New Catalog
Os.rmdir () Delete Empty directory (delete non-empty directory, use Shutil.rmtree ())
Os.makedirs () Create a Multilevel Catalog
Os.removedirs () Delete a multilevel directory
Os.stat (file) Get file properties
Os.chmod (file) Modify file Permissions
Os.utime (file) Modify file Timestamp
Os.name Gets the operating system identity,字符串指示当前使用平台。win->‘nt‘; Linux->‘posix‘
Os.sep 操作系统特定的路径分隔符,win下为"\\",Linux下为"/"
Os.linesep 当前平台使用的行终止符,win下为"\r\n",Linux下为"\n"
Os.pathsep String used to split the file path
Os.environ Get System Environment variables
Os.system () Executing operating system commands
OS.EXECVP () Start a new process
Os.access (path, mode) Determine file permissions
Os.wait () Waits for any one of the child processes to end, returning a tuple, including the process ID and exit status information for the child process

Three, Os.path module

Os.path.getctime () return file creation return file size byte unit build time floating point type os.path.getsize ()

Object Describe
Os.path.split (filename) Split the file path and filename (the last directory will be separated as the file name)
Os.path.splitext (filename) Splitting a file path and file name extension into a single tuple
Os.path.dirname (filename) Returns the directory portion of the file path
Os.path.basename (filename) Returns the filename portion of the file path
Os.path.join (Dirname,basename) Make the file path and filename into full file path
Os.path.abspath (name) Get absolute path
Os.path.splitunc (PATH) To split a path into a mount point and file name
Os.path.normpath (PATH) Canonical Path string form
Os.path.exists () Determine if a file or directory exists
Os.path.isabs () Returns true if path is an absolute path
Os.path.realpath (PATH) Returns the real path of a path
Os.path.relpath (path[, start]) Calculate relative path starting from start
Os.path.normcase (PATH) Convert the case and slash of path
Os.path.isdir (name) Determine if name is a directory, name is not a directory and return false
Os.path.isfile (name) Determine if name is not a file, there is no return false
Os.path.islink () Determines whether the file is connected to a file, returns a Boolean
Os.path.ismount () Specifies whether the path exists and is a mount point, returning a Boolean
Os.path.samefile () is the same path as the file that returns a Boolean
Os.path.getatime () Returns the most recent access time floating-point type
Os.path.getmtime () Returns the last modified time floating-point type
Os.path.getctime () Returns the file creation time floating point type
Os.path.getsize () Return File size byte units
Os.path.commonprefix (list) Returns the longest path in a list (multiple paths) that all paths share
Os.path.lexists Path exists returns true, path corruption also returns true
Os.path.expanduser (PATH) Convert the "~" and "~user" contained in path to the user directory
Os.path.expandvars (PATH) Replace the "$name" and "${name}" contained in path with the value of the environment variable
Os.path.sameopenfile (FP1, FP2) Determine if FP1 and FP2 point to the same file
Os.path.samestat (STAT1, STAT2) Determine if stat tuple STAT1 and Stat2 point to the same file
Os.path.splitdrive (PATH) Typically used under Windows, returns a tuple of drive names and paths
Os.path.walk (path, visit, ARG) Traverse path, execute a function for each path see manual for details
Os.path.supports_unicode_filenames Set whether Unicode path names are supported

Iv. Stat module: Describes the meaning of the values in the list of file attributes returned by Os.stat ()

Object Describe
Filestats = Os.stat (path) Gets the list of file attributes
Filestats[stat. St_mode] Get the mode of the file
Filestats[stat. St_size] File size
Filestats[stat. St_mtime] File Last Modified Time
Filestats[stat. St_atime] Last file access time
Filestats[stat. St_ctime] File creation time
Stat. S_isdir (Filestats[stat. St_mode]) Whether the directory
Stat. S_isreg (Filestats[stat. St_mode]) is General file
Stat. S_islnk (Filestats[stat. St_mode]) Whether to connect files
Stat. S_issock (Filestats[stat. St_mode]) Whether to cock files
Stat. S_isfifo (Filestats[stat. St_mode]) Whether to name the pipe
Stat. S_isblk (Filestats[stat. St_mode]) Whether the block device
Stat. S_ISCHR (Filestats[stat. St_mode]) Whether character settings

Python built-in modules

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.