Created
March 8, 2017 17:14
-
-
Save mingrammer/9a903a6b57fa40178e8bf9a706e296b2 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
# /opt/settings/config.py | |
DATABASE_CONFIG = { | |
'host': 'localhost', | |
'dbname': 'company', | |
'user': 'user', | |
'password': 'password', | |
'port': 3306 | |
} | |
# main.py | |
import sys | |
import pymysql | |
sys.path.append('/opt/settings') | |
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