|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> a=open('d:\\1.txt')
>>> b=a.read()
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
b=a.read() ###这一段报错
UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 10: illegal multibyte sequence
>>> b=a.read() ####这一段没有报错,两段是一模一模样的,为什么会这样?
>>> print (b)
######这个位置为什么没有打印出文件1.txt中的内容???
>>>
1,因为编码,open那里加一个参数:
2,你文件指针到末尾了,啥都读不出来,当然不会报错,
打印空内容也是同样的道理。
|
|