您的位置:首页 > 编程语言 > Python开发

Python问题:求助,在使用seek函数时,发现文件若有汉字,出现错误

2017-11-11 17:56 519 查看
这个是file文件:

第一行
第二行
第三行


代码:

f=open('file','r',encoding='utf-8')
f.seek(15)
print(f.tell())
print(f.readline())


出错:

Traceback (most recent call last):

15

  File "E:/py/day2/文件的seek,tell.py", line 7, in <module>

    print(f.readline())

  File "C:\Users\\AppData\Local\Programs\Python\Python35\lib\codecs.py", line 321, in decode

    (result, consumed) = self._buffer_decode(data, self.errors, final)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xac in position 0: invalid start byte

Process finished with exit code 1

另外,如果文件全都是英文,就不会出现问题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python
相关文章推荐