0

Syntax Error in opening an .txt file using Python open() function

Syntax Error in opening an .txt file using Python open() function in PyCharm IDE and IDLE also.I wrote following code file = open("C:\Users\Umang Goswami\Dekstop\Python File reading.txt","r") cont=file.read() print(cont) file.close() All code is as per SoloLearn lesson at https://www.sololearn.com/learn/Python/2446/ . SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape Process finished with exit code 1 Plz tell why code is not working , I am preety excited about this program.

8th Sep 2020, 1:14 PM
Umang Goswami
Umang Goswami - avatar
3 Réponses
+ 3
Avoid spaces in the file name 🤔 And if you can, then avoid that in path also!
8th Sep 2020, 1:19 PM
Namit Jain
Namit Jain - avatar
+ 1
Thanks problem solved by replacing \ with /
8th Sep 2020, 2:11 PM
Umang Goswami
Umang Goswami - avatar
0
I copy pasted that error and got a thread on stackoverflow for the same problem , https://stackoverflow.com/questions/37400974/unicode-error-unicodeescape-codec-cant-decode-bytes-in-position-2-3-trunca
8th Sep 2020, 1:19 PM
Abhay
Abhay - avatar