Python读取txt报错:'cp950' codec can't decode byte 0xb1 in position 5: illegal multibyte sequence

排错过程:
Python读取txt报错:‘cp950’ codec can’t decode byte 0xb1 in position 5: illegal multibyte sequence

for i in files:
	file_path = os.path.join(dirPath, i)
	for line in open(file_path, 'rt'):
		pass

修改代码,读取文件增加encoding='utf-8'参数,报错:‘utf-8’ codec can’t decode byte 0xa4 in position 39: invalid start byte

for i in files:
	file_path = os.path.join(dirPath, i)
	for line in open(file_path, 'rt', encoding='utf-8'):
		pass

根本原因:files中含有excel文件,切记细心!

你可能感兴趣的:(排错)