|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
list4可以正常输出print,想对list4内所有的数进行求和,再求平均
错误如下:
TypeError: unsupported operand type(s) for +: 'int' and 'list'
import codecs
import numpy as np
f = codecs.open(r'C:\Users\dukang\Desktop\polymertworatio\9:1\membrane.txt', mode='r', encoding='utf-8') # 打开txt文件,以‘utf-8'编码读取
line = f.readline() # 以行的形式进行读取文件
list4 = []
list5 = []
list6 = []
while line:
a = line.split()
b4 = a[3:4]
b5 = a[4:5]
b6 = a[5:6]
list4.append(b4)
list5.append(b5)
list6.append(b6)
line = f.readline()
f.close()
print(list4)#到这一步为止没有错误,部分输出结果如下[['20.2454'], ['23.7961'], ['18.9173'], ['19.1384'], ['20.8786'],
sumx = 0.0
sumx = sum(list4)#这里开始出错,TypeError: unsupported operand type(s) for +: 'int' and 'list'
|
|