【发布时间】:2015-06-03 13:15:56
【问题描述】:
问题: 代码编译得很好,但是当我调用 read_db_config 函数时,我得到“异常:在 mysql_config.ini 文件中找不到 mysql”
该文件在同一个目录中,但主脚本使用
运行两个目录import sys
from Config.MySQL.python_mysql_dbconfig import read_db_config
我是 python 新手,到处搜索,但我似乎无法确定我的问题
代码:
from ConfigParser import ConfigParser
def read_db_config(filename='mysql_config.ini', section='mysql'):
# create parser and read ini configuration file
parser = ConfigParser()
parser.read(filename)
# get section, default to mysql
db = {}
if parser.has_section(section):
items = parser.items(section)
for item in items:
db[item[0]] = item[1]
else:
raise Exception('{0} not found in the {1} file'.format(section, filename))
return db
mysql_config.ini:
[mysql]
database = testdba
user = root
password = test
unix_socket = /opt/lampp/var/mysql/mysql.sock
【问题讨论】:
标签: python