python os module summary

The python os module mainly manipulates files and directories. The commonly used methods are as follows:

# 1. os.getcwd() to get the directory where the current file is located 
# 2. os.makedirs('dirname1/dirname2') to create a directory, which can generate multiple recursive directories 
# 3. os.removedirs('dirname1/dirname2') to delete a directory , must be an empty directory 
# 4. os.mkdir() creates a single directory 
# 5. os.rmdir() deletes the empty directory, if there is no error 
# 6. os.listdir('dirname') lists all the files in the specified directory files and subdirectories, including hidden files, and print them as a list 
# 7, os.remove() removes files 
# 8, os.sep returns the file separator for the current system, \ for Windows, / 
# 9 for linux, os.linesep Output the line terminator used by the current platform, "\t\n" under win, "\n" under Linux 
# 10. os.pathsep Output the string used to split the file path as; under win, under Linux: 
# 11. os.environ gets system environment variables

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325352236&siteId=291194637