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'