Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ConfigParser
- class Section(object):
- def __init__(self,conf,section_name):
- self.conf = conf
- self.section = section_name
- def __getattr__(self,attr):
- print "getting the %s of the %s" % (attr,self.section)
- return self.conf.get(self.section,attr)
- class Configuration(object):
- def __init__(self,config_file):
- self.config_file = config_file
- self.parser = ConfigParser.ConfigParser()
- self.parser.read(self.config_file)
- def __getattr__(self,attr):
- print "getting the %s section" % (attr)
- return Section(self,attr)
- class App(object):
- def __init__(self):
- self.config = Configuration("/etc/infomaniak.conf")
- def start(self):
- bottle.run(host='',port=self.config.port)
- conf = app.Configuration("../../etc/server.conf")
- print conf.SERVER.PORT
- # ychaouche@ychaouche-PC ~/REPOS/INFOMANIAK-CLASSES/infomaniak/tests $ python test_config.py
- # getting the SERVER section
- # getting the PORT of the SERVER
- # getting the get section
- # Traceback (most recent call last):
- # File "test_config.py", line 5, in <module>
- # print conf.SERVER.PORT
- # File "../app.py", line 10, in __getattr__
- # return self.conf.get(self.section,attr)
- # TypeError: 'Section' object is not callable
- # ychaouche@ychaouche-PC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement