User:Reza1615/BOT/configReader.py
< User:Reza1615 | BOT
# -*- coding: utf-8 -*-
class Config:
"""Internal, reads config2uration from a file. Use the config2 object instead."""
config2 = {}
def __init__(self, uri):
self.config2File = uri
try:
execfile(self.config2File, {}, self.config2)
except IOError:
pass
def __getitem__(self, name):
return self.config2.get(name, None)
def __setitem__(self, name, value):
self.config2[name] = value
self._save()
def _save(self):
config2Str = ""
for i in self.config2:
config2Str += i+" = "+repr(self.config2[i])+"\n"
with open(self.config2File, 'w') as f:
f.write(config2Str)