Python os.path library function usage detailed introduction
os.path.dirname(path)
- Remove the file name and return to the directory
print(os.path.dirname("/Users/apple/test.py"))
/Users/apple
os.path.expanduser(path)
print(os.path.dirname("~/Documents"))
/Users/apple/Documents
os.path.abspath(path)
- Return the absolute path of the file
print(os.path.dirname("四叶"))
/Users/apple/Documents/四叶
os.path.basename(path)
- Return the file name at the end of the path (if the path ends with a'/', it returns empty)
print(os.path.dirname("~/Documents/test.py"))
test.py