Skip to content

Instantly share code, notes, and snippets.

@Everfighting
Created May 11, 2017 03:44
Show Gist options
  • Save Everfighting/db7b5805cb69328dbdc8bb0f90ce17ec to your computer and use it in GitHub Desktop.
Save Everfighting/db7b5805cb69328dbdc8bb0f90ce17ec to your computer and use it in GitHub Desktop.
读取配置文件转成json连接数据库
import psycopg2
import json
def load_db_config():
with open('../conf/db0.conf', "r") as f:
config_json = json.loads(f.read())
return config_json
config_json = load_db_config()
def handle_conn():
conn = psycopg2.connect(**config_json)
return conn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment