Skip to content

Instantly share code, notes, and snippets.

@ahmed4end
Created July 3, 2021 23:15
Show Gist options
  • Save ahmed4end/d1bb4e57bcde372205a1e1f9bbb1fc29 to your computer and use it in GitHub Desktop.
Save ahmed4end/d1bb4e57bcde372205a1e1f9bbb1fc29 to your computer and use it in GitHub Desktop.
configparser minimal example
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