Python OS Module Experiment Summary
1, Os.name (return to the platform being used, Linux display as "POSIX", Windows display as "NT")
>>> os.name'posix'
2, OS.GETCWD () (Display the current operating directory)
>>> os.getcwd ()'/root/test'
3, Os.listdir () (List all directories and files under the specified directory)
>>> Os.listdir ("/root/test") ['test.py' ' tab.py ' ' AA ' ' BB ' ' cc ' ' Tab.pyc ']
4, Os.remove () (delete the specified file under the directory)
>>> os.remove ("./test.py")>>> os.listdir ("/ Root/test") ['tab.py'aa' ' BB ' ' cc ' ' Tab.pyc ']
5, Os.mkdir () (Create directory)
>>> Os.mkdir ("mkdir")>>> Os.listdir (".")['tab.py','AA','BB','cc','Tab.pyc','mkdir']
6, Os.rmdir () (delete the specified directory)
>>> os.rmdir ( " mkdir " ) >>> Os.listdir ( " " ) [ " tab.py , " aa , " BB , " CC ", " tab.pyc "]
7, Os.path.isabs () (Judging if it is an absolute path) Os.path.isdir () (Judging whether it is a directory) Os.path.isfile () (Judging whether it is a file) Os.path.islink ( ) (Determine if it is a soft link) os.path.ismount () (Determine if the directory is a mount point)
>>> os.path.isfile ("tab.py") True>>> os.path.islink (" /etc/localtime") True>>> os.path.isabs ("/root/" ) True>>> Os.path.ismount ("/") True
8, Os.path.exists () (determine if the object exists)
>>> os.path.exists ("/root") True
9, Os.path.split () (returns the directory and file name of the object)
>>> os.path.split ("/root/test/tab.py") ('/root/test 'tab.py')
10. Os.system () (Executes the shell command and returns the result)
>>> Os.system ("Echo ' Hello world! ' " ) Hello world!
11, Os.chdir () (Toggle the current directory)
>>> Os.chdir ("/opt")>>> os.getcwd ()' /opt'
12, Os.path.join () (splicing directory and file name)
>>> Os.path.join ("/root/","test.py" )'/root/test.py'
13. Os.rename () (rename file)
>>> os.rename ("project1","project11")
"Learning" python (OS) module summary