【发布时间】:2018-08-31 11:05:18
【问题描述】:
我查看了使用 csv、txt、py 文件的各种解决方案,但无法完全完成我想要的,即:
- 我想将整数列表保存在单独的文件中
- 通过用户对单独文件的输入将新条目附加到列表中
- 并将更新后的版本以列表的形式读回,以 int 形式从该文件中进行计算。
我一直在尝试通过以下代码;
print('Enter the result of your last reading=')
newReading = input()
reading = [int(newReading)]
with open('avg.py', 'a') as f:
f.write('reading = ' . reading)
from avg.py import reading as my_list
print(my_list)
【问题讨论】:
-
欢迎来到 SO。请参阅How to Ask 和minimal reproducible example。此问题应包含样本输入数据和基于该样本的所需输出。您还可以展示您尝试过的内容以及遇到的问题。 SO 不是免费的代码编写服务。
标签: python python-3.x