【问题标题】:os.startfile error: FileNotFoundError: [WinError 2] The system cannot find the file specified:os.startfile 错误:FileNotFoundError: [WinError 2] 系统找不到指定的文件:
【发布时间】:2019-07-29 17:04:06
【问题描述】:

我在 Windows 7 上的 Spyder 中运行它。 我已经在多个不同类型的文件上对此进行了测试。

file = r'c/:folder/file.txt'
os.startfile(file)

返回

FileNotFoundError: [WinError 2] The system cannot find the file specified: 'c:/folder/file.txt'

我也试过检查文件名是否正确,os.path.isfile(file) 返回 True

【问题讨论】:

  • 如果你做file = r'c:\folder\file.txt'怎么办?我的意思是,我不明白为什么c: 后面没有斜线
  • 啊,我忘记打了。我使用的真实文件路径是从文件资源管理器中复制的。我搞砸了输入假地址。将编辑
  • 如果是 win 环境,为什么要使用指定的 unix 样式路径。试试,C:\folder\file.txt
  • 如果你尝试做os.startfile(os.path.normpath(file))?
  • C:\folder\file 很好用!我只是使用从复制和粘贴文件中复制的内容,并没有质疑它。我现在明白了,谢谢!

标签: python file spyder


【解决方案1】:

正如@olinox14 所说:

os.startfile(os.path.normpath(file))

很可能是读取路径文件有问题。 os 可以为你解决这个问题。我也遇到了同样的问题

【讨论】:

    猜你喜欢
    • 2017-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    • 2020-01-02
    相关资源
    最近更新 更多