Python Os.path module Common methods __python

Source: Internet
Author: User
Import OS

Os.path.join (a,b,c) #abc为str
Stitching paths

>>> os.path.join (' d:\\ ', ' f ', ' study ')
' d:\\f\\study '
>>> os.path.join (' A ', ' B ', ' V ')
' A\\b\\v '
Os.path.abspath (a)
Returns the absolute path of a
>>> os.path.abspath (' news.txt ')
' c:\\python34\\news.txt '
Os.path.split (PATH)
Split addresses into directories and file names to return
>>> os.path.split (' C:\Python34\Lib\dbm\gnu.py ')
(' c:\\python34\\lib\\dbm ', ' gnu.py ')
Os.path.dirname (PATH)
Returns the absolute address of the directory where path is located
>>> os.path.dirname (' C:\Python34\Lib\dbm\gnu.py ')
' c:\\python34\\lib\\dbm '
Os.path.basename (PATH)
Returns the last element, the filename
>>> os.path.basename (' C:\Python34\Lib\cgi.py ')
' cgi.py '
Os.path.exists (PATH)
To determine if the path exists, to return true if it exists, false if it does not exist
>>> os.path.exists (' d:\\f\study ')
True

Os.path.isabs (PATH)
Determines whether an absolute path, the return value bool

Os.path.isfile (PATH)
True to determine if path is a file

Os.path.isdir (PATH)
Path is a directory that already exists, return true, or false

Os.path.normcase (PATH)
Converts uppercase in path to lowercase and single slash to double slash

Os.path.getsize (PATH)
Returns the file size (in bytes) of path

Os.path.getatime (PATH)
Returns the last access time for path "return as timestamp"

Os.path.getmtime (PATH)
Returns the last modified time of path, "return as timestamp"

Official documents: https://docs.python.org/3.4/library/os.path.html

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.