查看: 8  |  回复: 0
  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...


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com