"Learning" python (OS) module summary

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.