我将如何存储值?

问题描述

所以我一直在尝试存储一个值,但是我意识到我只在打印它,我使用的是configupdater模块,我想知道如何在此处存储特定值:

updater.read('settings.ini')
g = updater['Trading Settings']['minimum_value_gain'].value
updater.update_file()
print(g)

Output:
5

值是5,但是随着我创建的一些代码的改变,它每5分钟更改一次,但是我想存储我拥有的值,例如,可以说它是5。 我的config.ini:

[Trading Settings]

#Shows the percentage of value you will be gaining from each trade (0.01 = 1%). Set to "none" to disable the limit.
minimum_value_gain = 5

解决方法

我看到您在project readme之后取得了一些成功,我认为这实际上是实现逻辑错误。

让我们看看你应该做什么

  1. 读取文件
  2. 更新值
  3. 写入新文件

现在您正在读取文件,并且有一个变量g用于引用updater['Trading Settings']['minimum_value_gain'].value

您实际上错过了第2步,因为您在这里从未修改任何内容,这是您应如何执行此操作的示例

# file unmodified,changes only the value associated with the
# updater object
updater['Trading Settings']['minimum_value_gain'].value = 6
# now we will update the file with the changed value
updater.update_file() # or updater.write('path/to/some/new/file')

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...