Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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 3.x 为什么说没有这样的文件或目录,而它显然是该目录中的一个文件?_Python 3.x_File - Fatal编程技术网

Python 3.x 为什么说没有这样的文件或目录,而它显然是该目录中的一个文件?

Python 3.x 为什么说没有这样的文件或目录,而它显然是该目录中的一个文件?,python-3.x,file,Python 3.x,File,这怎么可能不起作用 classes = [] with open(r'D:/classes.txt', 'r') as f: for line in f: print(line) classes.append(line) for c in classes: print(c) 您是否偶然使用了Linux的Windows子系统?如果是这样的话,我认为除了C:\…这不应该是反斜杠,或者Windows Python可以使用正斜杠吗?@Carl:它可以使用正斜杠。

这怎么可能不起作用

classes = []
with open(r'D:/classes.txt', 'r') as f:
    for line in f:
        print(line)
        classes.append(line)
for c in classes:
print(c)

您是否偶然使用了Linux的Windows子系统?如果是这样的话,我认为除了C:\…这不应该是反斜杠,或者Windows Python可以使用正斜杠吗?@Carl:它可以使用正斜杠。我知道在Windows中看到这一点很奇怪。支持正斜杠的有趣之处在于不需要使用原始字符串。除非你愿意。
FileNotFoundError: [Errno 2] No such file or directory: 'D:/classes.txt'