我的Dbconn
班级有以下构造函数:
def __init__(self):
self.host = "localhost"
self.database = "my_database"
self.username = "username"
self.password = "password"
try:
self.db = MySQLdb.connect(
self.host,
self.username,
self.password,
self.database
)
self.cursor = self.db.cursor()
except:
print "There was an error while connecting to the database"
self.db.rollback()
但是,当我执行程序时,我得到:
File "database.py", line 39, in __init__
self.db.rollback()
AttributeError: Dbconn instance has no attribute 'db'
任何线索为什么我得到那个?