这是场景,我有两个脚本可以说 abc.py 和 xyz.py
使用 abc.py 我想每隔一秒更新一次配置文件。这是示例代码。
ABC.PY
while True:
cfgfile=config.read("config.ini")
config.set('section','option',Value)
with open('config.ini', 'w') as configfile:
config.write(configfile)
time.sleep(1)
在 Xyz.py 上,我想从 config.ini 中获取值。我在XYZ.PY上的代码
import configparser
file = input("Enter the file name: ")
config = configparser.ConfigParser()
cfgfile = config.read("config.ini")
values = config.get(file, 'option')
print(values)
但问题是,ABC.py只更新了一次配置文件!这意味着它仅在 First While 循环中更新文件。它不会像我想的那样每秒更新配置文件。
猛跑小猪
相关分类