>>> f = open('E:\\record.txt')
>>> f
<_io.TextIOWrapper name='E:\\record.txt' mode='r' encoding='cp936'>
>>> f.read()
''
>>> f.read()
Traceback (most recent call last):
File "" , line 1, in <module>
f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa0 in position 8: incomplete multibyte sequence
出现报错,看弹幕提示说需要加
'r'
变成
f=open ('E:\\record.txt.txt','r')
结果依然报错
>>> f=open ('E:\\record.txt.txt','r')
>>> f.read()
Traceback (most recent call last):
File "" , line 1, in <module>
f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 4: illegal multibyte sequence
csdn上找到有前辈的经验贴,试了一下成功了,原理还是不懂但是最起码能够读写文件了
编译成功的代码如下:
>>> f=open('E:\\record.txt.txt','r',encoding='utf-8')
>>> f.read()
'小客服:小啊基于,小甲鱼,你好\n小甲鱼:你好----丑'
想看前辈文章可以戳这里的的链接