我编写了一个生成这样的文件的代码
import sys
file = open('output.txt','w')
x = [1,2,3,4,5,6,7,8,9,10]
f = [i**2 for i in x]
g = [i**3/100 for i in x]
strlist = list(map(str,f))
strlist1 = list(map(str,g))
file.write(','.join(strlist))
file.write('\n')
file.write('.'.join(strlist1))
结果是(文件内容)
1,4,9,16,25,36,49,64,81,100
0.01.0.08.0.27.0.64.1.25.2.16.3.43.5.12.7.29.10.0
我想将此文件作为整数读取以制作这样的列表
[1,4,9,16,25,36,49,64,81,100]
[0.01.0.08.0.27.0.64.1.25.2.16.3.43.5.12.7.29.10.0]
我尝试时遇到此错误
with open('output.txt','r') as a:
data = a.readlines()[0]
with open('output.txt','r') as a:
data1 = a.readlines()[1]
intlist = []
intlist.append(data)
['1,4,9,16,25,36,49,64,81,100\n']
['0.01.0.08.0.27.0.64.1.25.2.16.3.43.5.12.7.29.10.0']
我该如何修复它?
犯罪嫌疑人X
绝地无双
相关分类