Advertisement
j7sx

read config

Feb 9th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. #!/usr/bin/python
  2. #--*--coding: utf-8--*--
  3.  
  4. import ConfigParser
  5.  
  6. def read_param(filename='config.ini', section='mysql'):
  7.     config = ConfigParser.ConfigParser()
  8.     config.read('config.ini')
  9.     db ={}
  10.     if config.has_section(section):
  11.         items = config.items(section)
  12.         for item in items:
  13.             db[item[0]] = item[1]
  14.     else:
  15.         raise Exception('{0} not found in the {1} file'.format(section, filename))
  16.     print db
  17.  
  18. read_param()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement