python basis of Chapter XVIII ------------- path module: os.path

Path Module: os.path

Package guide: import os

abspath (Path *): to convert the relative path to absolute path (path can easily write)

OS Import 
# os.path.abspath with RES = ( '1.py')
# Print (RES)
outputs: D: \ SZC \ 1.py

basename (path): Get the path of the main part (the path can easily write)

Os.path.basename RES = # ( 'D: \\ 2.py the SZC \\') 
# Print (RES)
outputs: 2.py

dirname (path): Get the path portion of the path (path can easily write)

Os.path.dirname RES = # ( 'D: \\ 2.py the SZC \\') 
# Print (RES)
outputs: D: \ SZC

join (path a, two paths): merge two paths (the path of return output b)

The os.path.join RES = # ( 'D: \\ the SZC \ QWE', 'D: \\ \\ the SZC 1234') 
# Print (RES)
outputs: D: \ SZC \ 1234

split (path): path split into path portion and a body portion consisting of a tuple (Note: The return value is a tuple, str in the split returns a list of)

The os.path.split RES = # ( 'D: \\ \\ QWE the SZC') 
# Print (RES)
outputs :( 'D: \\ SZC', 'QWE')

splitext (path): the file extension path split and part of the other tuple (Note: The return value is a tuple, will show no suffix '')

os.path.splitext = RES ( 'D: \\ \\ 123.py the SZC') 
Print (RES)
outputs :( 'D: \\ SZC \\ 123 ', '.py')

Gets the size of the file: getsize (path)  

res = os.path.getsize ( 'D: \\ SZC \\ 14 \\ Chapter members built .py') 
Print (RES)

isdir (path): testing whether you are a folder (Note: The return value is bool, the path to real and to return True as a folder)

os.path.isdir = nothing ( "D: \\ \\ SZC第14章') 
print (anything)

isfile (path): detect whether a file (Note: The return value is bool, the path is real and file to return True)

 

res = os.path.isfile ( 'D: \\ SZC \\ 14 \\ Chapter members built .py') 
Print (RES)

 

getctime (path): Get file creation time (return value is the timestamp file was created)

 

# Res = os.path.getctime ( 'D: \\ SZC \\ \\ Chapter 14 Built-member .py') 
# Print (RES)

 

getmtime (path): Get file modification time (return value is the timestamp to modify the file)

 

# Res = os.path.getmtime ( 'D: \\ SZC \\ \\ Chapter 14 Built-member .py') 
# Print (RES)

 

getatime (path): Get the file access time (return value is a timestamp to access the file)

 

# Res = os.path.getatime ( 'D: \\ SZC \\ \\ Chapter 14 Built-member .py') 
# Print (RES)

 

exits (path): detecting whether it is the presence of the specified path (return value bool)

 

# Res = os.path.exists ( 'D: \\ SZC \\ \\ Chapter 14 Built-member .py') 
# Print (RES)

 

isabs (Path): detecting whether the path is an absolute path (return value bool)

 

# = Nothing os.path.isabs ( "D: \\ \\ 12312344 SZC ') 
# print (anything)

 

sameFile (path a, two paths): detecting whether two paths point to the same file or folder (return value is bool)

 

# Res = os.path.samefile ( './ Chapter 14 / member of the built .py', 'D: \\ SZC \\ 14 \\ Chapter members built .py') 
# Print (RES)

 

 





 

Guess you like

Origin www.cnblogs.com/szc-boke/p/11265753.html