Pythonで計算した計算結果をテキストファイルに出力したいのですが,
AttributeError: 'float' object has no attribute 'write'
というエラーが出ます.
該当のソースコード
python 2.7
def main():
file_start = 1 file_end = 10 folder_start = 1 folder_end = 4 f = open('z_value.txt', 'w') for i in range(file_start, file_end + 1): F_temp = [] for j in range(folder_start, folder_end + 1): for line in open('med%d/prop%03d.txt' %(j, i), 'r'): data = line.split() F_temp += [float(data[3])] F_temp = np.array(F_temp) a = -10e-18 b = -1.5e-14 c = 3.5e-10 d = 5.6e-07 e = 0.004 f = 34.41 z_pos = a*F_temp**5 + b*F_temp**4 + c*F_temp**3 + d*F_temp**2 + e*F_temp + f z_std = np.std(z_pos) z_temp = 80* 1.1 * (i - 1) f.write('%f %f \n' %(z_temp, z_std)) f.close()
main()
prop%d.txtにはfloat型の数値が4列ずつ並んでいます.
↓こんな感じ
81.000000 39.000000 2.076923 -5040.000000
79.000000 38.000000 2.078947 -4797.000000
80.000000 38.000000 2.105263 -4956.000000
おそらくz_tempとz_stdの型に問題があるとは思うのですが,何をどう書き換えればいいかわかりません.
よろしくお願いします.

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/25 13:09