os basic introduction to the library
os library provides a common, basic interactive features of the operating system (windows, mac os, linux)
-os library is a python standard library contains hundreds of functions
- related to the operating system, including common path operations, process management, and other environmental parameters
among them:
- Path Operation: os.path sub-libraries, file path and information processing
- Process Management: Start the system in other programs
- environmental parameters: access to environmental information and other parameters of the system hardware and software
A Path operation
os.path inlet path to the sub-bank, and the process for operating the file path; herein refers to a path
Directory or file path contains a file name
import os.path
import os.path as op
1. os.path.abspath (path) Returns the path, an absolute path of the current system
2.os.path.normpath (path) normalized path representation, with uniform division path \\
>>>os.path.normpath("D://PYE//file.txt")
'D:\\PYE\\file\\file.txxt'
3.os.path.relpath (path) Returns a relative path (relative path) between the current program and the file
4.os.path.dirname (path) Returns the name of the directory path in
5.os.path.basename (path) Returns the path of the last file name
6.os.path.join (path, * paths) in combination with a path paths, a return path string
7.os.path.exists (path) is determined path corresponding to the file or directory exists, returns True or False
8.os.path.isfile (path) determines whether a corresponding file path already exists, returns True or False
Whether the directory already exists, returns True or False 9.os.path.isdir (path) is determined path corresponding
10.os.path.getatime (path) returns once the path corresponding to the file or directory access time
11.os.path.getatime (path) returns one of the access time (access) on the path corresponding to the file or directory
12.os.path.getmtime (path) Returns the path corresponding to the file or directory last modified time (modify)
13.os.path.getctime (path) Returns the creation time of the corresponding file or directory path (create)
14.os.path.getsize (path) Returns the path corresponding to the size of the file, in bytes
II. Process Management
1.os.system(command)
- execute a program or command conmmand
- in the windows system, the return value of calling cmd return information
III. Environmental parameters
1.os.chdir (path) to modify the path of the current program operations
2.os.getcwd () returns the program of the current path
3.os.getlogin () to get the current system login user name
The number of cpu 4.os.cpu_count () of the current system will
5.os.urandom (n) to obtain n random string of bytes length, typically for encryption and decryption algorithm