Python module learning: OS module

Source: Internet
Author: User

I. Overview of OS Modules

The Python OS module contains common operating system features. For example, copying files, creating files and folders ...

Second, common methods

1, Os.listdir () returns all file and directory names under the specified directory.

2, Os.remove () delete a file.

3, Os.system () run the shell command.

4. The Os.path.split () function returns the directory name and file name of a path

5, Os.path.isfile () and Os.path.isdir () function respectively check whether the given path is a file or directory, the return value is Ture or false

6, Os.path. The exists() function is used to verify that the given path exists and that the return value is Ture or FALSE, respectively.

7, Os.path.getsize (name) get file size, if name is directory return 0L

8. Os.path.splitext () detach file name and extension

9. Os.path.join (path,name) connection directory with file name or directory

10. Os.path.basename (path) returns the file name

11, Os.path.dirname (path) return file path

Python module learning: OS module

Related Article

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.