新建了一个txt文本,内容为“1234”,保存的时候选择编码格式为utf-8,但是还是无法读取,以及路径里的/和\有没有区别,我试了两种路径报错内容不一样,请问老师问题出在哪
with open('C:\Users\HF\Desktop\test.txt', 'r') as f: ... f.read() ... File "<stdin>", line 1 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape with open('C:/Users/HF/Desktop/test.txt', 'r') as f: ... f.read() ... Traceback (most recent call last): File "<stdin>", line 2, in <module> UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 2: illegal multibyte sequence
with open('C:\Users\HF\Desktop\test.txt', 'r') as f: ... f.read() ... File "<stdin>", line 1 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
with open('C:/Users/HF/Desktop/test.txt', 'r') as f: ... f.read() ... Traceback (most recent call last): File "<stdin>", line 2, in <module> UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 2: illegal multibyte sequence
先用纯英文的文件试,再研究编码问题
Sign in to make a reply
凡仔荡微博
新建了一个txt文本,内容为“1234”,保存的时候选择编码格式为utf-8,但是还是无法读取,以及路径里的/和\有没有区别,我试了两种路径报错内容不一样,请问老师问题出在哪