The OS module of the Python-based module

Source: Internet
Author: User

The OS module of the Python-based module

The role of the OS module:

OS, the semantics of the operating system, so it must be operating system-related functions, can handle files and directories we need to do daily manual operations, such as: Display the current directory of all files/delete a file/get file Size ...

In addition, the OS module is not limited by the platform, that is to say: when we want to display the current command in Linux to use the PWD command, and the Windows CMD command line will use this, the amount ... I wipe, I really do not know, (no matter what, certainly not pwd), this time we use the Python OS module Os.path.abspath (name) feature, no matter whether Linux or Windows can get the current absolute path.

Common features of the OS module:

1 Os.name #显示当前使用的平台

>>> os.name ' nt ' #这表示Windows >>> os.name ' POSIX ' #这表示Linux

2 OS.GETCWD () #显示当前python脚本工作路径

>>> os.getcwd () ' c:\\users\\capital-d\\pycharmprojects\\untitled ' #使用pycharm >>> os.getcwd () '/ Root ' #Linux平台在/root directory directly using the Python3 command


The OS module of the Python-based module

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.