- 帖子
- 14
- 精华
- 0
- 积分
- 103
- 阅读权限
- 20
- 注册时间
- 2019-11-5
- 最后登录
- 2020-1-15
|
#! /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
好像是文字无法识别来着,怎么解决啊?????
|
|