Guest User

Untitled

a guest
Jan 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. [mysql]
  2. host = localhost
  3. database = python_mysql
  4. user = root
  5. password =
  6.  
  7. def read_db_config(filename='config.ini', section='mysql'):
  8.  
  9. parser = ConfigParser()
  10. parser.read(filename)
  11.  
  12. db = {}
  13. if parser.has_section(section):
  14. items = parser.items(section)
  15. for item in items:
  16. db[item[0]] = item[1]
  17. else:
  18. raise Exception('{0} not found in the {1} file'.format(section, filename))
  19.  
  20. return db
  21.  
  22. ...
  23. conn = mysql.connector.connect(host='localhost',
  24. database='python_mysql',
  25. user='root',
  26. password='secret')
  27. ...
Add Comment
Please, Sign In to add comment