os.path module is mainly used to acquire properties file.
The following are several common methods os.path module:
method | Explanation |
---|---|
os.path.abspath(path) | Returns the absolute path |
os.path.basename(path) | Returns the file name |
os.path.commonprefix(list) | Return list (multiple paths), all of the common path of the longest path |
os.path.dirname(path) | Returns the file path |
os.path.exists(path) | If the path path exists, returns True; path if the path does not exist, returns False. |
os.path.lexists | Returns True path exists, the path returns True damage |
os.path.expanduser(path) | The path contains "-" and "- User" is converted into the user directory |
os.path.expandvars(path) | According to an alternative "$ name" included in the path and the value of the environment variable "$ {name}" |
os.path.getatime(path) | Returns the last access time (floating-point number of seconds) |
os.path.getmtime(path) | Returns last file modification time |
os.path.getctime(path) | Returns the file path creation time |
os.path.getsize(path) | Returns the file size, file does not exist if it returns an error |
os.path.isabs(path) | Determine whether the absolute path |
os.path.isfile(path) | Determine whether the file path |
os.path.isdir(path) | Determine whether the directory path |
os.path.islink(path) | Determine whether the link path |
os.path.ismount(path) | Determining whether the path is a mount point |
os.path.join(path1[, path2[, ...]]) | The synthesis of a directory and file name path |
os.path.normcase(path) | Conversion path capitalization and slash |
os.path.normpath(path) | Specification path string |
os.path.realpath(path) | Return true path path |
os.path.relpath(path[, start]) | Counted from the start relative path |
Oskpthksmefaile (Pthl, Pth2) | Determine whether the same file or directory |
os.path.sameopenfile(fp1, fp2) | Fp1 and fp2 point to determine whether the same file |
os.path.samestat (stat1, stat2) | Judgment stat tuple stat1 and stat2 point to the same file |
os.path.split(path) | The path is divided into dirname and basename, returns a tuple |
os.path.splitdrive(path) | Generally used in the windows, the drive and path returns a tuple |
os.path.splitext(path) | Split path, return path and file name extensions tuple |
os.path.splitunc(path) | The route into a mount point and file |
os.path.walk(path, visit, arg) | Traversal path, into each directory function calls the visit, visit function must have three parameters (arg, dirname, names), dirname represents the directory name of the current directory, names on behalf of all the files in the current directory name, args, compared walk of The third parameter |
os.path.supports_unicode_filenames | Set support unicode path name |