Created
July 3, 2021 23:15
-
-
Save ahmed4end/d1bb4e57bcde372205a1e1f9bbb1fc29 to your computer and use it in GitHub Desktop.
configparser minimal example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import configparser | |
class Config: | |
FILENAME = 'CONFIG.INI' | |
def __init__(self): | |
self.config = configparser.ConfigParser() | |
self.read() | |
def read(self): | |
self.config.read(self.FILENAME) | |
def save(self): | |
try: | |
with open(self.FILENAME, 'w') as configfile: | |
self.config.write(configfile) | |
except: | |
print('WTF') | |
def append(self, **kwargs): | |
for k,v in kwargs.items(): | |
self.config['DEFAULT'][k] = str(v) | |
if __name__ == '__main__': | |
config = Config() | |
config.append(user='ahmed', age='dead', hope=0) | |
config.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment