Created
March 8, 2017 03:53
-
-
Save mingrammer/dd6779a14c85f3b36b2ee6717a197289 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config.py | |
DATABASE_CONFIG = { | |
'host': 'localhost', | |
'dbname': 'company', | |
'user': 'user', | |
'password': 'password', | |
'port': 3306 | |
} | |
# main.py | |
import pymysql | |
import config | |
def connect_db(dbname): | |
if dbname != config.DATABASE_CONFIG['dbname']: | |
raise ValueError("Couldn't not find DB with given name") | |
conn = pymysql.connect(host=config.DATABASE_CONFIG['host'], | |
user=config.DATABASE_CONFIG['user'], | |
password=config.DATABASE_CONFIG['password'], | |
db=config.DATABASE_CONFIG['dbname']) | |
return conn | |
connect_db('company') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment