【问题标题】:Errno 2 python File not found errorErrno 2 python 文件未找到错误
【发布时间】:2016-11-29 15:46:40
【问题描述】:

节目是

with open ('D:\\Users\\gracelewis\\Desktop\\data\\input_data2.txt','r') as data2:
    with open ('D:\\Users\\gracelewis\\Desktop\\data\\input_names.txt','r') as names:
        with open ('D:\\Users\\gracelewis\\data\\output_data_merged.txt','w') as output_data: 
            tempstring1 = (data2.readlines())
            tempstring2 = (names.readlines())
            list1 = list(tempstring1)
            list2 = list(tempstring2)
            mulitilist1 = (list1+list2)
            print(multilist1)
            output_data.writelines(multilist)

我收到了这个错误-

Traceback (most recent call last):
  File "/Users/gracelewis/Documents/Documents/University/data/Option2.py", line 2, in <module>
    with open ('D:\\Users\\gracelewis\\Desktop\\data\\input_data2.txt','r') as data2:
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\Users\\gracelewis\\Desktop\\data\\input_data2.txt'

【问题讨论】:

  • 面对现实:你的文件不存在
  • 错误提示的文件input_data2.txt不存在,请检查完整路径。
  • 顺便说一句,您可以使用原始前缀来避免双斜杠:例如:r"D:\temp\xxx"
  • 文件肯定存在

标签: python errno pyzo


【解决方案1】:

这正是它所说的 - 你没有文件路径的文件

'D:\\Users\\gracelewis\\Desktop\\data\\input_data2.txt'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-05
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 2023-01-04
    • 2019-03-01
    • 1970-01-01
    • 2020-06-05
    相关资源
    最近更新 更多