1 def __init__(self): 2 # 获取setting主机名 端口号和数据库名 3 self.host = settings[‘MySQL_HOST‘] 4 self.port = settings[‘MySQL_PORT‘] 5 self.dbname = settings[‘MySQL_DBNAME‘] 6 self.conn = MySQLdb.connect(host=‘localhost‘, port=3306, db=‘douban‘, user=‘root‘, passwd=‘root‘,charset=‘utf8‘) 7 self.cur = self.conn.cursor()