mm1 = [line.strip() for line in open("m1.dat", 'r')]
ii1 = [int(x) for x in mm1]
s1 = 1
er1 = 0.022
er2 = 2.866
w = [1,2,5,6]
f=open('newdat.txt','w')
for item in ii1:
for i in w:
if i == 1:
f.write(s1,item,1,list1[item-1],er2)
elif i == 2:
f.write(s1,item,2,list2[item-1],er1)
elif i == 5:
f.write(s1,item,5,list3[item-1],er2)
else:
f.write(s1,item,6,list4[item-1],er1)
但我得到我應該如何格式化我的文件?
TypeError: function takes exactly 1 argument (5 given)
我明白,我需要格式化我寫,但怎麼樣?
['join'](https://docs.python.org/3/library/stdtypes.html#str.join)them,'f.write(「,」。join(s1,item,1, list1 [item-1],er2))' –
or python3 use print(s1,item,6,list,er,file = f,sep =',') – user234461