When python struggles: Attribute Errors
matt
matt at greenroom.com.au
Tue Dec 17 08:22:45 EST 2002
I have a problem where the code:
# ------ begin code ------
class DBInitializer:
def init(self, db_name, host, user="", password=""):
# Connect to host
if not self.status("Connecting to host: %s..." % host, \
self.connect(host, user, password)):
...
self.cursor = self.db.cursor()
...
def connect(self, host, user, password):
try:
self.db = MySQLdb.connect(host, user, password)
...
# ------ end code ------
raises an Attribute Error.
I tried putting "self.db=None" just before the self.status call but
this only raised another Attribute Error complaining that "None" has
no attribute "cursor".
The problem is that I can't instantiate the result of
MySQLdb.connect() without the possibility or raising an error which i
intend to catch in the self.connect method.
It's frustrating because if i were using C++ i could simply type "db =
(MySQLdb_Connection*)0;" (or whatever the connection object would be
called).
Can anyone think of a way to get around this while retaining the
connect method within self.status.
Any Ideas?
Thanks in advance,
-- matt (matt at greenroom.com.au)
More information about the Python-list
mailing list