我在Python3中打开一个文本文件时遇到了一个问题:我想打开一个我之前创建的文本文件,它的名称是"pythontest“。该文件包含一些数字和单词。为了在Python中打开它,我这样做: with open ('pythontest.txt') as test:
file = test.read()
print(file) 但是Python给了我这个错误: FileNotFoundError: [Errno 2] No such file or directory: 'pythontest.txt 我如何修复这个错误?提前谢谢。
在Python中,我有一个脚本,我正在尝试使用python命令来打开我在Python脚本目录中的open("data.csv")文件。
那里有一个名为data.csv的文件。
python脚本指出了一个错误:
Error in Python IOError: [Errno 2] No such file or directory: 'data.csv'
这个错误意味着什么?我该如何修复它?
以下是重现错误的脚本中的最小代码:
open("data.csv")
以下是该文件夹的结构: - python
- python study
- study.py
- a.txt study.py中的代码是: import os
if(os.path.exists("a.txt")):
print("YES") # my real code is not this
else:
print("NO") 通常我会以pycharm项目的形式打开python study文件夹,如下所示: ? 结果就是YES。 但今天我无意中打开了python文件夹(而不是python study)作
在Mac上工作时,我的桌面上有单独的.py文件,在终端中输入以下内容时,这些文件会打开并运行良好:
cd desktop
python3 filename.py
现在,我在桌面上创建了一个名为Python的文件夹,以更好地存储这些文件,但无论我尝试了什么,我似乎都无法访问它。我试过以下几种方法
cd desktop/Python (file or directory doesn't exist)
cd desktop/Python python3 filename.py (file or directory doesn't exist)
有什么想法吗?
我在Windows7上运行Anaconda2,在命令提示符下运行"python“时遇到了问题。
我将"C:\ProgramData\Anaconda2“添加到环境变量中的PATH,它允许我从CMD运行"python”。但是,只有当我通过单击Start、键入cmd并按enter来运行它时,这才适用于CMD。如果我从窗口点击并选择"Open command window here“并尝试运行python,我得到错误信息"'python‘is shift+right’is shift+right as a internal or external co