Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- provided an ini file as follows:
- [main]
- content_root: /srv/webroot/content/files
- content_layout: flat
- db_name: FamilyPhoto
- db_user: root
- db_password: password
- db_server: localhost
- $ python getconfig.py
- /srv/webroot/content/files
- '''
- import ConfigParser
- def ConfigSectionMap(section):
- dict1 = {}
- Config = ConfigParser.ConfigParser()
- Config.read('photo.cfg')
- options = Config.options(section)
- for option in options:
- try:
- dict1[option] = Config.get(section, option)
- if dict1[option] == -1:
- DebugPrint("skip: %s" % option)
- except:
- print("exception on %s!" % option)
- dict1[option] = None
- return dict1
- if __name__ == '__main__':
- Name = ConfigSectionMap("main")['content_root']
- print Name
Add Comment
Please, Sign In to add comment