首页 /编程语言和算法/Python
 py 分离路径和文件名
昨天 16:59
import os # 导入 os 模块,用于与操作系统进行交互,例如执行系统命令

strPathAndFile=r"C:\Tools\abc.txt"
strPath, strFile = os.path.split(strPathAndFile)
print(strPath) # C:\Tools
print(strFile) # abc.txt

input("Press Enter to exit...")

运行结果:

C:\Tools
abc.txt
Press Enter to exit...


 
全部回复(0)
首页 | 电脑版 |