Description of common functions of the Python OS module, and functions of the pythonos Module

Source: Internet
Author: User

Description of common functions of the Python OS module, and functions of the pythonos Module

The OS module in the Python standard library contains common operating system functions. This module is especially important if you want your program to be unrelated to the platform. That is, it allows a program to run in Linux and Windows without any changes or any problems.

The following lists some useful parts in the OS module. Most of them are simple and clear.
 

OS. sepIt can replace the path separator specified by the operating system. \ In windows

OS. nameString indicates the platform you are using. For example, for Windows, it is 'nt ', and for Linux/Unix users, it is 'posix '.

OS. getcwd ()Function to get the current working directory, that is, the directory path of the current Python script.

OS. getenv ()Obtain an environment variable. If none is not returned

OS. putenv (key, value)Set an environment variable value

OS. listdir (path)Returns the names of all objects and directories in the specified directory.

OS. remove (path)The function is used to delete an object.

OS. system (command)Function is used to run shell commands.

OS. linesepString indicates the row Terminator used by the current platform. For example, in Windows, '\ r \ n' is used, in Linux,' \ n' is used, and in Mac, '\ R' is used '.

OS. path. split (p)The function returns the directory name and file name of a path.

OS. path. isfile ()AndOS. path. isdir ()Check whether the given path is a file or a directory.

OS. path. existe ()Function is used to check whether the given path actually exists.

OS. curdir:Returns the current directory ('.')
OS. chdir (dirname ):Change the working directory to dirname

OS. path. getsize (name ):Get the file size. If the name is a directory, return 0L

OS. path. abspath (name ):Obtain absolute path
OS. path. normpath (path ):Standard path string format

OS. path. splitext ():Separating file names and extensions
OS. path. join (path, name ):Connection directory and file name or directory
OS. path. basename (path ):Returned file name
OS. path. dirname (path ):Returned file path

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.