Os.path module is mainly used for file property acquisition, often used in programming, the following are several common methods of this module. More ways to view official documents: http://docs.python.org/library/os.path.html
1.os.path.abspath (PATH) Returns the absolute 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 ' 2.os.path.split (path) divides the path into directory and filename two-tuple returns. >>> os.path.split (' C:\\csv\\test.csv ') (' C:\\csv ', ' test.csv ') > >> os.path.split (' c:\\csv\\ ') (' c:\\csv ', ') 3.os.path.dirname (path) Returns the directory of path. is actually the first element of Os.path.split (path). >>> os.path.dirname (' c:\\csv\test.csv ') ' c:\\ ' >>> Os.path.dirname (' c:\\csv ') ' c:\\ ' 4.os.path.basename (path) Returns the filename of the last path. How the path ends with/or, the null value is returned. 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 treated as filename) >>> os.path.basename (' c:\\csv\\ ') ' 5.os.path.commonprefix (list) Returns the longest path shared by all paths in the list. such as: >>> os.path.commonprefix (['/home/td ', '/home/td/ff ', '/home/td/fff ']) '/ Home/td ' 6.os.path.exists (path) Returns true if path exists, false if path does not exist. >>> os.path.exists (' c:\\ ') true >>> os.path.exists (' c:\\csv\ \test.csv ') false 7.os.path.isabs (PATH) Returns True if path is an absolute path. 8.os.path.isfile (path) Returns True if path is a file that exists. otherwise returns false. >>> os.path.isfile (' C:\\Boot.ini ') true >>> os.path.isfile (' C:\\csv\\test.csv ') false >>> os.path.isfile (' c:\\csv\\ ') false