При открытии моего приложения загружается файл конфигурации. json.
def load_profiledata(self):
self.log_print("Loading profiles...")
self.config = {}
try:
with open('./config.json', 'r+') as f:
self.config = json.load(f)
self.container.value_prof.set(self.config['prof'])
self.container.value_name.set(self.config['name'])
self.container.value_email.set(self.config['email'])
self.container.value_phone.set(self.config['phone'])
self.container.value_addr1.set(self.config['addr1'])
self.container.value_addr2.set(self.config['addr2'])
self.container.value_zip.set(self.config['zip'])
self.container.value_cardnumber.set(self.config['cardnumber'])
self.container.value_cardexpmonth.set(self.config['cardexpmonth'])
self.container.value_cardexpyear.set(self.config['cardexpyear'])
self.container.value_cardcode.set(self.config['cardcode'])
self.log_print("loaded config.json")
except Exception:
self.log_print("failed to load profile")
self.save_profile()
Мне нужна кнопка save_profile
внутри моего gui, чтобы создать новый файл json с теми же полями .
def save_profile(self):
self.config['prof'] = self.container.value_prof.get()
self.config['name'] = self.container.value_name.get()
self.config['email'] = self.container.value_email.get()
self.config['phone'] = self.container.value_phone.get()
self.config['addr1'] = self.container.value_addr1.get()
self.config['addr2'] = self.container.value_addr2.get()
self.config['zip'] = self.container.value_zip.get()
self.config['cardnumber'] = self.container.value_cardnumber.get()
self.config['cardexpmonth'] = self.container.value_cardexpmonth.get()
self.config['cardexpyear'] = self.container.value_cardexpyear.get()
self.config['cardcode'] = self.container.value_cardcode.get()
with open('./config.json', 'w') as f:
json.dump(self.config, f)
self.log_print("profile saved")
self.profiles_print(self.container.value_prof.get())
Как мне создать новый файл json, имя файла которого равно self.container.value_prof.get()
? возможно ли это ... в python
помощь приветствуется. спасибо!