https://blog.csdn.net/dingmanzzz/article/details/113449275
if __name__ == '__main__': pa = r'C:\Users\hha\Desktop\002594.txt' # 获取文件路径 print(os.path.dirname(pa)) # C:\Users\hha\Desktop # 获取文件名 print(os.path.basename(pa)) # 002594.txt # 路径与文件名合成 print(os.path.join(os.path.dirname(pa), os.path.basename(pa))) # C:\Users\hha\Desktop\002594.txt