My .ini data is essential to my python application. the configparser array/data is not available globally
import configparser
def write_config():
config = configparser.ConfigParser()
with open('config.ini', 'w') as configfile:
config.write(configfile)
def read_config():
config = configparser.ConfigParser()
config.sections()
config.read('config.ini')
# things are fine here
print(config['DEFAULT']['G'])
read_config()
#here, or from other functions, I cannot access or modify config like
print(config['DEFAULT']['G'])
#I would also like to change config anywhere in app
config['DEFAULT']['G']="100"
#then just call write_config
write_config()
What is the proper way to make my way (with functions) work? I do realize that skipping those functions and making the program flat would workaround the problem. I do know how to make a variable global, but I am apparently unable to make a variable in a function/external library global