Skip to content

Instantly share code, notes, and snippets.

@perone
Created September 13, 2012 19:26
Show Gist options
  • Save perone/3716939 to your computer and use it in GitHub Desktop.
Save perone/3716939 to your computer and use it in GitHub Desktop.
ConfigParser attrib
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