Python没有打开我选择的文件

2024-05-26 11:13:06 发布

您现在位置:Python中文网/ 问答频道 /正文

代码:

os.startfile("C:\finished.py")

退货:

FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\**x0cinished**.py'

期望值:取C:\完成.py你知道吗

是什么导致python这样更改我的输入?你知道吗


Tags: the代码pyosfindsystemfilespecified
2条回答

您需要转义“\”字符。写“C:\\完成.py“在startfile语句中。他说

'\f'是一个特殊字符(参见Table of escape sequences)。在使用硬编码路径时,应该养成使用r(原始字符串)的习惯:

os.startfile(r"C:\finished.py")

相关问题 更多 >