I have the problem while openning file in https://www.programiz.com/python-programming/online-compiler/ IDE The code is below f=open("E:\note/p.txt",'r') print(f.read())
but getting the error Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: 'E:\note/p.txt'
Please help me to solve this problem Thanks
You have a newline character in your filename. Try this:
f = open(r'E:\note\p.txt')
By using a raw string, the 'n' is not escaped and therefore the backslash (Windows directory separator) is used literally.
Note that 'r' mode is default and therefore not required
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.