這是場景,我有兩個腳本可以說 abc.py 和 xyz.py使用 abc.py 我想每隔一秒更新一次配置文件。這是示例代碼。ABC.PYwhile 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 configparserfile = input("Enter the file name: ")config = configparser.ConfigParser()cfgfile = config.read("config.ini")values = config.get(file, 'option')print(values)但問題是,ABC.py只更新了一次配置文件!這意味著它僅在 First While 循環中更新文件。它不會像我想的那樣每秒更新配置文件。
如何在while循環上更新配置文件并同時從不同的腳本中獲取值?
慕尼黑5688855
2022-06-02 14:31:33