Created
September 13, 2012 19:26
-
-
Save perone/3716939 to your computer and use it in GitHub Desktop.
ConfigParser attrib
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 AttrDict(dict): | |
def __getattr__(self, key): | |
d = AttrDict() | |
for k in self.keys(): | |
if k.startswith(key): | |
dcoup = k[len(key)+1:] | |
if not dcoup: | |
return self[k] | |
else: | |
d[dcoup] = self[k] | |
return d | |
class HappyRaw(ConfigParser.RawConfigParser): | |
def __getattr__(self, key): | |
return self._sections[key] | |
config = HappyRaw(dict_type=AttrDict) | |
config.read('conf.ini') | |
print config.base.resources |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment