To whomever it concerns, the linked answers do not work! Dear admin, what changes do I need to do to get this back open?
Can not get python to open a file in a directory no matter what I try. It is a json file in known location.
I'm on windows 10, I am making my first python file using Visual Studio Code.
I've tried all iterations I can think of: \\, //, /
, with and without r. It just won't accept the path or does something weird to it.
I know this is super simple issue and there are tons of solutions for it but they just don't work.
I have tried the 3 solutions from the supposed linked solution, none work:
Error messages with different syntax:
1:
with open(r"C:\Path\Sam\about\cs\ffiles\up\u_file.json") as open_file:
data = open_file.read()
file_data = json.loads(data)
print(file_data)
I get:
Traceback (most recent call last):
File "d:\...\test1.py", line 45, in <module>
with open(r"C:\Path\Sam\about\cs\ffiles\up\u_file.json") as open_file:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Path\\Sam\\about\\cs\\ffiles\\up\\u_file.json'
Another try, different syntax:
with open("C:\\Path\\Sam\\about\\cs\\ffiles\\up\\u_file.json") as open_file:
data = open_file.read()
file_data = json.loads(data)
print(file_data)
I get:
File "d:\...\test1.py", line 45
with open("C:\\Path\\Sam\\about\\cs\\ffiles\\up\\u_file.json") as open_file:
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 85-86: truncated \uXXXX escape
PS D:\...>
Third example of the supposed solution, does not work either:
with open("C:\Path\Sam\about\cs\ffiles\up\u_file.json") as open_file:
data = open_file.read()
file_data = json.loads(data)
print(file_data)
I get:
Traceback (most recent call last):
File "d: ...test1.py", line 45, in <module>
with open("C:\Path\Sam\about\cs\ffiles\up\u_file.json") as open_file:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Path\Sam\about\cs\ffiles\up\u_file.json'
PS D:\...>
The file path is 100% correct. I can copy the path, press win-r, paste the path and windows opens the file.