赞
踩
- with open("input.txt") as f:
- for line in f:
- print(line)
按行读取文本文件时报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position...
python的open方法默认编码取决于平台,如果是windows平台,默认编码是gbk,如果文件是utf8编码,就会报这个错误。
解决办法:
- with open("input.txt",encoding='utf-8') as f:
- for line in f:
- print(line)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。