python - IO错误: Errno 2 No such file or directory python

标签 python

我已经确认“apples.txt”确实存在。我的代码有什么问题吗?

   def Loadfile(fileName):
        myfile=open(fileName,'r')
        next(myfile)
        for line in myfile:
            linesplit=line.split()
            print line

    print Loadfile('apples.txt')

最佳答案

该文件可能不在您的 working directory 中。将工作目录更改为 apples.txt 所在位置,或提供文件的完整路径,例如 'C:\\folder\\subfolder\\apples.txt'

关于python - IO错误: Errno 2 No such file or directory python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29493444/

相关文章:

python - 如何在Python中找到列表的中位数

python - 在 Kivy for Python 中按下按钮时更新标签的文本

python - 一个长期的难题,如何优化python中的多级循环?

python - 鉴于两个项目不能在同一个列表中,如何获得列表的所有组合?

python - 从给定的 n 个点中选择最远的 k 个点

python - 使用pysftp拆分SFTP目录下的文本文件

python - 为什么在创建 OptionGroup 时必须提供解析器两次?

列表和子列表的Python算法

python - pandas to_sql 引发错误 'Identifier name is too long'

python - 如何使用 Python 库(例如 Paramiko)与 Telnet 和 SSH 进行链式连接