'Not able to open local txt file in online python compiler

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 "<string>", line 1, in <module> FileNotFoundError: [Errno 2] No such file or directory: 'E:\\note/p.txt'

Please help me to solve this problem Thanks



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Albert Winestein