我将如何存储值?

问题描述

所以我一直在尝试存储一个值,但是我意识到我只在打印它,我使用的是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')