One, OS module
1.os.name
The output string indicates the platform being used. If the window is ' NT ', it is ' POSIX ' for Linux/unix users.
2.OS.GETCWD ()
The function gets the current working directory, which is the directory path of the current Python script work.
3.os.listdir (' D:\python ')
Lists all files under the specified directory.
4.os.remove (' Test.txt ')
Delete a file, delete only the file
5.os.rmdir (' Test ')
Delete a folder, delete only the folder
6.os.removedirs (' Python/code ')
Delete folders recursively, note that only empty directories can be deleted
7.os.mkdir (' MLL ')
Create a folder
8.os.makedirs (' Mll/test ')
Recursive creation of folders, when creating folders, if the parent directory does not exist will automatically help you create the parent directory
9.os.sep
Take the path delimiter of the current operating system
10.os.rename (' test1 ', ' test2 ')
Rename the file test1 to Test2
11.os.stat (' homework1.py ')
Get file information
12.os.linesep
Gets the line break for the current operating system
13.os.pathsep
The delimiter for each path in the current system environment variable, Windows is;, Linux is:
14.os.environ
Environment variables for the current system
15.os.system (' ipconfig ')
Start DOS, execute operating system commands, but get no results
res = Popen (' ipconfig '). Read ()
Print (RES)
16.os.path.abspath (file)
Get file Absolute path
17.os.path.split (' d:/syz_python/code/day6/review. Py ')
Split path and file name
18.os.path.dirname (' D:/syz_python/code/day6 ')
Get the parent directory and get his top level directory
19.os.path.basename (' D:/syz_python/code/day6 ')
Gets the last level, if the file displays the filename, if the directory displays the directory name,
20.os.path.exists (' D:/syz_python/code/day6 ')
If the file/directory exists, there is a return of true, there is no return false
21.os.path.isabs (' D:/syz_python/code/day6 ')
To determine if it is an absolute path, yes to return true, not to return false
22.os.path.isfile (' xiaohei.py ')
Determine if it is a file: 1. The file must exist; 2. must be a file. Yes returns true, not just returns false
23.os.path.isdir (' D:/syz_python/code ')
Determines whether a path exists or not. Yes returns true, not just returns false
24.os.path.getsize (' homework.py ')
Get File size
25.os.path.join (' d:/', ' python/', ' MLL ', ' test.py ')
Stitching into a path
26.os.walk (R ' D:\syz_python\code\day6\test ')
Get content under Directory
Abs_path the absolute path of the current loop
Dir directory below all folders []
All files under file directory []
Second, sys module
1.sys.path
Path is a directory listing from which Python looks for third-party extensions. When Python starts, Sys.path is initialized according to the built-in rules, pythonpath variables.
2.sys.path.insert (0, ' test ')
Insert Test at the beginning of path and then import test without an error, such as introducing the other module, because the error is not added to the environment variable.
3.os.path.append (' a.py ')
Python files are also introduced into the Python environment variable, but inserted in the last
Python (v) OS and SYS modules for common modules