Official documentation: Http://docs.python.org/library/ OS .path.html
Reprinted from: http://www.redicecn.com/html/Python/20110507/273.html
OS. Path. abspath (PATH)
Returns the absolute path of path normalization.
>>> OS .path.abspath('test.csv ')
'C: \ python25 \ test.csv'
>>> OS. Path. abspath ('C: \ test.csv ')
'C: \ test.csv'
>>> OS. Path. abspath ('../CSV \ test.csv ')
'C: \ CSV \ test.csv'
OS. Path. Split (PATH)
Split the path into two groups: Directory and file name.
>>> OS. Path. Split ('C: \ CSV \ test.csv ')
('C: \ CSV ', 'test.csv ')
>>> OS. Path. Split ('C: \ CSV \\')
('C: \ CSV ','')
OS. Path. dirname (PATH)
Returns the path directory. It is actually the first element of OS. Path. Split (PATH.
>>> OS. Path. dirname ('C: \ CSV \ test.csv ')
'C :\\'
>>> OS. Path. dirname ('C: \ CSV ')
'C :\\'
OS. Path. basename (PATH)
Returns the final file name of the path. If the path ends with a slash (/) or slash (\), a null value is returned. That is, the second element of OS. Path. Split (PATH.
>>> OS. Path. basename ('C: \ test.csv ')
'Test.csv'
>>> OS. Path. basename ('C: \ csv ')
'Csv' (here CSV is processed as a file name)
>>> OS. Path. basename ('C: \ CSV \\')
''
OS. Path. commonprefix (list)
Returns the longest path of all paths in the list.
For example:
>>> OS. Path. commonprefix (['/home/TD', '/home/TD/ff','/home/TD/fff'])
'/Home/TD'
OS. Path. exists (PATH)
If the path exists, true is returned. If the path does not exist, false is returned.
>>> OS. Path. exists ('C :\\')
True
>>> OS. Path. exists ('C: \ CSV \ test.csv ')
False
OS. Path. isabs (PATH)
Returns true if path is an absolute path.
OS. Path. isfile (PATH)
Returns true if path is an existing file. Otherwise, false is returned.
>>> OS. Path. isfile ('C: \ Boot. ini ')
True
>>> OS. Path. isfile ('C: \ CSV \ test.csv ')
False
>>> OS. Path. isfile ('C: \ CSV \\')
False
OS. Path. isdir (PATH)
If path is an existing Directory, true is returned. Otherwise, false is returned.
>>> OS. Path. isdir ('C :\\')
True
>>> OS. Path. isdir ('C: \ CSV \\')
False
>>> OS. Path. isdir ('C: \ windows \ test.csv ')
False
OS. Path. Join (path1 [, path2 [,...])
After multiple paths are combined, the parameters before the first absolute path are ignored.
>>> OS. Path. Join ('C: \ ', 'csv', 'test.csv ')
'C: \ CSV \ test.csv'
>>> OS. Path. Join ('windows \ Temp ', 'c: \', 'csv', 'test.csv ')
'C: \ CSV \ test.csv'
>>> OS. Path. Join ('/home/A','/home/AA/BB ','/home/AA/BB/C ')
'/Home/AA/BB/C'
OS. Path. normcase (PATH)
On Linux and Mac platforms, this function returns the path as it is. On Windows platforms, All characters in the path are converted to lowercase letters, and all slashes are converted to slashes.
>>> OS. Path. normcase ('C:/Windows \ system32 \\')
'C: \ Windows \ system32 \\'
OS. Path. normpath (PATH)
Canonicalized path.
>>> OS. Path. normpath ('C: // Windows \ system32 \ ../temp /')
'C: \ Windows \ Temp'
OS. Path. splitdrive (PATH)
>>> OS. Path. splitdrive ('C: \ Windows ')
('C: ',' \ Windows ')
OS. Path. splitext (PATH)
>>> OS. Path. splitext ('C: \ CSV \ test.csv ')
('C: \ CSV \ test', '.csv ')
OS. Path. getsize (PATH)
Returns the size (in bytes) of the path file ).
>>> OS. Path. getsize ('C: \ Boot. ini ')
299l