Guest User

Untitled

a guest
Sep 12th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. '''
  2. provided an ini file as follows:
  3. [main]
  4. content_root: /srv/webroot/content/files
  5. content_layout: flat
  6. db_name: FamilyPhoto
  7. db_user: root
  8. db_password: password
  9. db_server: localhost
  10.  
  11. $ python getconfig.py
  12. /srv/webroot/content/files
  13. '''
  14.  
  15. import ConfigParser
  16.  
  17. def ConfigSectionMap(section):
  18. dict1 = {}
  19. Config = ConfigParser.ConfigParser()
  20. Config.read('photo.cfg')
  21. options = Config.options(section)
  22. for option in options:
  23. try:
  24. dict1[option] = Config.get(section, option)
  25. if dict1[option] == -1:
  26. DebugPrint("skip: %s" % option)
  27. except:
  28. print("exception on %s!" % option)
  29. dict1[option] = None
  30. return dict1
  31.  
  32.  
  33. if __name__ == '__main__':
  34. Name = ConfigSectionMap("main")['content_root']
  35. print Name
Add Comment
Please, Sign In to add comment