Python Os.path module function function

Source: Internet
Author: User

1, Os.path.abspath (path)

Gets the absolute path, which is actually equal to OS.GETCWD () +path

2, Os.path.basename (path)
Take the last file or filename of the path. If path ends with a/, then a null value is returned, relative to Os.path.dirname (path), and the path part is returned.

3. Os.path.commonprefix (list)
Returns the longest path common to all paths in the list.

4, os.path.exists (path)
True if path exists, or if path does not exist or does not have permission to execute Os.stat (), or if the corrupted link returns false

5, os.path.lexists (path)
Unlike os.path.exists (path), if there is a broken link, it returns true

6, Os.path.expanduser (path)
Replace the user's home directory with the ~ etc

7, Os.path.expandvars (PATH)
Accept the extension of environment variation, you can use environment variables in path

8, Os.path.getatime (PATH)
Returns the last time the path was entered. A is access, the same as the atime inside Linux.

9, Os.path.getmtime (PATH)
Returns the time of the last modification of this path. M I think is make, also with Linux

10, Os.path.getctime (PATH)
Returns the creation time of path

11, Os.path.isabs (PATH)
Returns true if path is an absolute path

12, Os.path.isfile (PATH)
Returns true if path is a regular file. Similar to Os.path.isdir (path), Os.path.islink (path), Os.path.ismount (path)

13, Os.path.join ()

Merge paths

14, Os.path.relpath (path[, start])
Returns a "related path", either the current directory or an optional start

15, Os.path.samefile (path1, path2)
If path1 and path2 are the same file or directory, return True

16, Os.path.sameopenfile (FP1, FP2)
Returns True if FP1 and FP2 point to the same file

17, Os.path.samestat (STAT1, STAT2)
If the stat tuple STAT1 and Stat2 point to the same file, the return is true. The stat tuple structure is generated by Fstat (), Lstat (), stat ()

18, Os.path.walk (Top,func,arg)

Top: Path

Func: Represents a callback function that processes a traversal path. The so-called callback function is used as a parameter of a function, and when a certain time is triggered, the program invokes a defined callback function to process a task. The callback function must provide 3 parameters: the 1th parameter is the walk () parameter tag, The 2nd parameter represents a list of directories, and the 3rd parameter represents a list of files

ARG: The parameter arg is a tuple that is passed to the callback parameter func. One parameter of the callback function must be ARG, which provides the processing parameters for the callback function. parameter arg can be null

19, Os.path.normcase (PATH)

On a case-insensitive file system, it converts the path to lowercase letters. On Windows, it converts a forward slash to a backslash.

20, Os.path.split (Path), Os.path.splittext (path)

Split () splits the path part and the filename section into tuples; Splittext (path) splits the extension and non-extension parts into tuples

21, Os.path.getsize (PATH)

Return file size

Python Os.path module function function

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.