Small ape circle python learning - system call os module

os module provides a number of functions of the program allow you to interact directly with the operating system

Get the current working directory, that directory path of the current Python script work: os.getcwd ()
returns all files and directories in the specified directory: os.listdir ()
function is used to delete a file: os.remove ()
to delete more Contents: os.removedirs: (r "c \ python")
given path if a file: os.path.isfile ()
whether the given path is a directory: os.path.isdir ()
to determine whether It is an absolute path: os.path.isabs ()
whether the given path really exist: os.path.exists ()
returns a directory path and file names: os.path.split () eg os.path.split ( '/home/swaroop/byte/code/poem.txt') results: ( '/ home / swaroop / byte / code', 'poem.txt')
separating extension: os.path.splitext () eg os. path.splitext ( '/ usr / local / test.py') results: ( '/ usr / local / test', '.py')
to obtain the pathname: os.path.dirname ()
to get the absolute path: os.path .abspath ()
Gets the file name: os.path.basename ()
run shell commands: os.system ()
reads the value of the operating system environment variable HOME: os.getenv ( "HOME")
returns all of the operating system environment variables: os.environ
Set system environment variables, is only valid when program running: os.environ.setdefault ( 'HOME', ' / home / alex')
gives the current line terminator platform: os.linesep Windows using '\ r \ n', Linux and MAC use '\ n'
indicates the platform you are using: os.name for Windows, it is 'nt', and for Linux / Unix users, it is 'posix'
rename: os.rename (old, new)
create multi-level directory: os.makedirs (r "c: \ python \ test")
to create a single directory: os.mkdir ( "test")
getting file attributes: os.stat (file)
to modify file permissions and timestamps: os. chmod (file)
get file size: os.path.getsize (filename)
combined with the directory name and file name: os.path.join (dir, filename)
change the working directory to dirname: os.chdir (dirname)
to get the size of the current terminal : os.get_terminal_size ()
to kill the process: os.kill (10884, signal.SIGKILL)

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_44867000/article/details/91864393