from configparser import ConfigParser import os static = """ [general] name = phone = email = theme = dark [apps] dhiraagu = 1 ooredoo = 1 hdc = 1 mwsc = 1 stelco = 1 medianet = 1 [dhiraagu] phone = otp = token = account = [ooredoo] phone = otp = cookie = [hdc] property = nid = [mwsc] meter_no = account_no = mobile_no = [stelco] account_no = bill_no = [medianet] account_no = nid = phone = """ class Config(ConfigParser): def __init__(self) -> None: super().__init__() if not os.path.exists('config.ini'): self.initialize(content=static) self.read('config.ini') def initialize(self, content): with open('config.ini', 'a+') as file: file.write(content) def save(self, section, key, value): config.set(section, key, value) with open('config.ini', 'w') as configfile: self.write(configfile) self.read('config.ini') config = Config()