Answer the question
In order to leave comments, you need to log in
How to change the values of variables through another python file?
I'm trying to implement saving settings to another python file, but in vain. Google didn't help.
Data.py settings file (may be needed):
level = 1 # Уровень
music = True # Включена ли музыка
sfx = True # Спецэффекты
Answer the question
In order to leave comments, you need to log in
Of the simple options
1. configparser
Automatically reads and writes changed values to files of the format
variable = value
2. json
We store our changed variables in a dictionary and write / read to the json file.
import json
config = {
"level": 1,
"music": True,
"sfx": True,
}
# запись
with open("config.json", "w") as f:
json.dump(config, f)
# чтение
with open("config.json") as f:
config = json.load(f)
# использование соответственно в виде словаря
config['level'] = 3
And why in the Piston file?
Save to some CSV and don't suffer. Plus, Piston has ready-made libraries for working with configs.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question