This seems like it should be very easy:
f = open(\'C:\\Users\\john\\Desktop\\text.txt\', \'r\')
But I am getting this error:
In Windows, paths use backslash. But if a string that must represent a path contains characters such as '\r' , '\t' , '\n' .... etc there will be this kind of problem. This is the precise reason why your string fails to represent a path.
In the absence of these problematic characters, there will be no problem. If they are present, you must escape the backslashes or use a raw string r'C:\Users\john\Desktop\text.txt'