无法在联机python编译器中打开本地txt文件



我在中打开文件时遇到问题https://www.programiz.com/python-programming/online-compiler/IDE代码低于

f=open("E:\note/p.txt",'r')
print(f.read())

但是得到错误Traceback (most recent call last): File "<string>", line 1, in <module> FileNotFoundError: [Errno 2] No such file or directory: 'E:\note/p.txt'

请帮我解决这个问题感谢

文件名中有一个换行符。试试这个:

f = open(r'E:notep.txt')

通过使用原始字符串,"n"不会被转义,因此反斜杠(Windows目录分隔符(是按字面意思使用的。

注意,"r"模式是默认模式,因此不需要

最新更新