conn_file.cfg:
[user]
connectString=host="192.xx.xx.xx",user="user",passwd="pw",db="college"
db_parser.py
import ConfigParser as cp
import MySQLdb as ms
config = cp.ConfigParser()
config.read(r".\conn_file.cfg")
connectString = config.get('user','connectString')
con = ms.connect(connectString)
print(con)
错误:
Traceback (most recent call last):
File "db_parser.py", line 6, in <module>
connectString = config.get('user','connectString')
File "/usr/lib64/python2.7/ConfigParser.py", line 607, in get
raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'user'