相关疑难解决方法(0)

Python open()给出IOError:Errno 2没有这样的文件或目录

出于某种原因,我的代码无法打开一个简单的文件:

这是代码:

file1 = open('recentlyUpdated.yaml')
Run Code Online (Sandbox Code Playgroud)

错误是:

IOError: [Errno 2] No such file or directory: 'recentlyUpdated.yaml'
Run Code Online (Sandbox Code Playgroud)
  • 当然,我检查了这是文件的正确名称.
  • 我试过移动文件,给出文件open()的完整路径,似乎没有任何工作.

python file-io file filenotfoundexception file-not-found

56
推荐指数
3
解决办法
30万
查看次数

我在一个简单的 Python open() 函数上收到 File not Found 错误

这是我将其归结为简单的 open() 的代码,打开文件输入语句显示但关闭文件没有。这在空闲界面中运行,但不在命令行界面中运行。

程序和文件(拼写正确且全部小写)都在桌面上用于此测试。有没有人看到缺少什么?打开

# Read It
# Demonstrates reading from a text file

input("\n\nPress the enter key to Open file")
print("Opening and closing the file.")
text_file = open("nicole1.txt", "r")
input("\n\nPress the enter key to Close file")
text_file.close()

input("\n\nPress the enter key to exit.")
Run Code Online (Sandbox Code Playgroud)

** 更新,好的,我尝试了绝对路径,没有成功。我在闪存驱动器上有一个副本。我在 Windows XP 机器和 Windows 7 机器上运行它,它运行得很好。我使用相同的闪存驱动器并尝试在 Windows10 Box 上运行它,但我遇到了问题。一条评论询问是否有回溯,并且有,它基本上表明该文件不存在。我现在正在尝试确定这是否是 Windows 10 问题。此外,代码将在两个 Windows Box(XP 和 Win10)上的 idle 内运行。

python file windows-10

7
推荐指数
1
解决办法
3万
查看次数

VSCode 中 Python 无法识别相对文件路径

当我使用绝对路径时,代码工作正常,但使用相对路径会在 python 中抛出 FileNotFoundError 。

 f = open("Input.txt","r")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

python file visual-studio-code

1
推荐指数
1
解决办法
1万
查看次数