Python Basic-os module

Source: Internet
Author: User

The OS module provides a number of features that allow your program to interact directly with the operating system

Gets the current working directory, which is the directory path of the current Python interpreter work: OS. getcwd() returns all file and directory names under the specified directory: OS. listdir() function to delete a file: OS. remove() Delete multiple directories: OS. Removedirs (r "C:\python") verifies whether the given path is a file: OS. path. isfile(Verify that the given path is a directory: OS. path. isdir() to determine if it is an absolute path: OS. path. isabs() to verify that the given path is actually stored in the: OS. path. exists() returns the directory name and file name of a path: OS. path. split() E. G OS. path. split('/home/swaroop/byte/code/poem.txt 'Results('/home/swaroop/byte/code ',' Poem.txt ') Detach extension: OS. path. splitext() E. G OS. path. splitext('/usr/local/test.py 'Results('/usr/local/test ','. Py 'Get path name: OS. path. dirname() to obtain an absolute path: OS. path. abspath() Get file name: OS. path. basename() to run the shell command: OS. system(Read the operating system environment variable home value: OS. getenv("HOME") returns all environment variables for the operating system: OS. Environ set the system environment variable, only valid when the program is running: OS. Environ. SetDefault(' HOME ','/home/alex ') gives the line terminator used by the current platform: OS. Linesep Windows uses' \ r \ n ', Linuxand Mac use' \ n ' indicates the platform you are using: OS. name for Windows, which is' NT ', and for Linux/unix User, it is' POSIX ' rename: os. Rename (old, new) create a multilevel directory: OS. Makedirs (r "C:\python\test") Create a single directory: OS. mkdir ("test") Get file properties: OS. stat ("file") modifying file permissions and timestamps: OS. chmod (file) Get file size: OS. path.getsize (filename) combined with directory name and file name: Os.path.join (Dir,filename: Os (Dirname.get_terminal_size  (: Os.kill (10884,signal) 


Python base-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.