首页 > 解决方案 > 我需要帮助将数据附加到文本文件中

问题描述

Temp = int(input("Temp: "))
Humid = int(input("Humidity: "))
Wind = int(input("Wind: "))
new_data = [Temp, Humid, Wind]
if Temp < 120 and Temp > 0 and Humid < 120 and Humid > 0 and Wind < 120 and Wind > 0:
   with open('C:/Users/amaya/OneDrive/Desktop/CIS 2300/Test_file.txt', 'a') as f:
       new_data.append(f)
       print("ok will append new data")       
else:
    print("The numbers are to high/low.")
    pass

您好,我正在尝试将“new_data”附加到 test_file 中,但不断收到此错误“AttributeError:'_io.TextIOWrapper' 对象没有属性'append'”。我在输入 f.append(new_data) 时遇到了同样的错误。 提前致谢 :)

标签: pythonappendtext-files

解决方案


推荐阅读