Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-FileNotFoundError:[Errno 2]没有这样的文件或目录:';y';_Python - Fatal编程技术网

Python-FileNotFoundError:[Errno 2]没有这样的文件或目录:';y';

Python-FileNotFoundError:[Errno 2]没有这样的文件或目录:';y';,python,Python,我得到了以下错误: fileRef = open(the_file, "r") # opening file to be read 我不是想粗鲁什么的,但是错误信息是非常清楚的。错误本身FileNotFoundError意味着在您告诉程序要查找的位置找不到您请求的文件。如果我有一个文件夹,里面有文件a、b和c,我要求打开y,我会预料到这个错误。因为y不是a,b或c 假设从您提供的代码中,_文件的值是“y”,那么您要求Python查找执行程序的位置(我假设Python的行为是这样的)。如果

我得到了以下错误:

fileRef = open(the_file, "r")    # opening file to be read

我不是想粗鲁什么的,但是错误信息是非常清楚的。错误本身
FileNotFoundError
意味着在您告诉程序要查找的位置找不到您请求的文件。如果我有一个文件夹,里面有文件
a
b
c
,我要求打开
y
,我会预料到这个错误。因为
y
不是
a
b
c


假设从您提供的代码中,_文件的值是
“y”
,那么您要求Python查找执行程序的位置(我假设Python的行为是这样的)。如果您确实有一个名为
y
的文件,那么我建议您将其移动到您想要执行的位置,或者移动到该位置并执行Python代码(以最适合您需要的为准)。

如果
文件
'y'
并且不存在具有此名称的文件,您将得到此错误。我假定
'y'
是文件名,错误本身会告诉您出了什么问题<代码>“没有“y”您是否阅读了错误消息?
FileNotFoundError: [Errno 2] No such file or directory: 'y'