#path is the file path
f=open(‘C:\Users\jingqiu\Desktop\New Text Document.txt’)
SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
The file path plus r becomes f=open(r‘C:\Users\jingqiu\Desktop\New Text Document.txt’)
or f=open(‘C:\\Users\\jingqiu\\Desktop\\New Text Document.txt’)
the output of f.read() is …
Traceback (most recent call last):
File “<pyshell#4>”, line 1, in <module>
f.read()
File “C:\Users\xiuwe\AppData\Local\Programs\Python\Python37\lib\encodings\cp1252.py”, line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x8d in position 17: character maps to <undefined>
encode issue
f = open(r’C:\Users\jingqiu\Desktop\New Text Document.txt’,encoding=’utf-8′)
f.read()
OK ^_^
Similar Posts:
- [Solved] Unicode decode error in the background when the robot framework is running
- [Solved] Python error: UnicodeDecodeError:’gbk’ codec can’t decode byte 0xb0 in position 166: illegal multibyte sequence
- [Solved] Error when Python reads a file Unicode decodeerror
- Error in reading Chinese path of pydev in eclipse
- [Solved] Python Error: UnicodeDecodeError: ‘gb2312’ codec can’t decode byte 0xa4 in position… : illegal multibyte sequence
- [Solved] UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa5 in position 1508: illegal multibyte sequence
- python3 are installed through pip on Win 10, Unicode decodeerror: ‘UTF-8’ codec can’t decode byte
- Python: How to Solve raise JSONDecodeError(“Expecting value”, s, err.value) from None json.decoder…
- Python Files Error: SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: tr
- [Solved] UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x80 in position 128: illegal multibyte sequence