|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- open('E:\\歌词.txt')
- <_io.TextIOWrapper name='E:\\歌词.txt' mode='r' encoding='cp936'>
- >>> f = open('E:\\歌词.txt')
- >>> f
- <_io.TextIOWrapper name='E:\\歌词.txt' mode='r' encoding='cp936'>
- >>> f.read()
- Traceback (most recent call last):
- File "<pyshell#3>", line 1, in <module>
- f.read()
- UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 8: illegal multibyte sequence
- >>> f.readline()
- ''
- >>> f = open('E:\\歌词.txt')
- >>> r = f.read()
- Traceback (most recent call last):
- File "<pyshell#6>", line 1, in <module>
- r = f.read()
- UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 8: illegal multibyte sequence
- >>> f
- <_io.TextIOWrapper name='E:\\歌词.txt' mode='r' encoding='cp936'>
- >>> f.read(5)
复制代码
如题,在之后加上f.read(5)返回的是空的,而我的文档里是有字符的。我的是windows系统。 感谢!
再 open 里面加上个 encoding 的参数 设置编码为 utf-8 试试看
- f = open('E:\\歌词.txt',encoding='utf-8')
复制代码
如果还是报错 那么就打开记事本 将另存为时候 设置下编码 为 Unicode
|
|