Crossin的编程教室
标题:
编码识别问题!!
[打印本页]
作者:
落梦
时间:
2019-12-1 23:23
标题:
编码识别问题!!
#! /usr/bin/python
# -*- coding: utf-8 -*-
f =
open
(
'scores.txt'
)
lines = f.readlines()
f.close()
results = []
for
line
in
lines:
data = line.split()
sum =
0
for
score
in
data[
1
:]:
sum +=
int
(score)
result =
'%s
\t
: %d
\n
'
%(data[
0
]
,
sum)
#print result
results.append(resut)
output =
open
(
'scores.txt'
,
'w'
)
output.writelines(results)
output.close()
-------------------------------------------------------------------------------------------------------------------------------------
"C:\Program Files\Python38\python.exe" C:/Users/23593/Desktop/.idea/python练习/处理文件中的数据.py
Traceback (most recent call last):
File "C:/Users/23593/Desktop/.idea/python练习/处理文件中的数据.py", line 4, in <module>
lines = f.readlines()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x8a in position 2: illegal multibyte sequence
好像是文字无法识别来着,怎么解决啊?????
作者:
crossin先生
时间:
2019-12-2 14:26
改成 f = open('scores.txt', encoding='utf8')
作者:
落梦
时间:
2019-12-2 23:09
好了,谢谢
欢迎光临 Crossin的编程教室 (https://bbs.crossincode.com/)
Powered by Discuz! X2.5