When python struggles: Attribute Errors
Cliff Wells
LogiplexSoftware at earthlink.net
Tue Dec 17 18:03:49 EST 2002
On Tue, 2002-12-17 at 14:27, matt wrote:
> Cliff Wells <LogiplexSoftware at earthlink.net> wrote in message news:<mailman.1040147656.20827.python-list at python.org>...
> > And then you would call cursor = db.cursor? Sounds fishy. If an object
> > fails in its initialization, continuing as if nothing had gone wrong
> > seems like a bad idea. If the "DBInitializer" object fails to
> > initialize, what good is it?
> Actually, inside the if statement was a return; call. I apologise for
> leaving it out.
Ah, so actually the code looks something like this?
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)):
return
self.cursor = self.db.cursor()
...
def connect(self, host, user, password):
try:
self.db = MySQLdb.connect(host, user, password)
except SomeError:
return 0
else:
return 1
def status(self, message, retVal):
print message
return retVal
???
> I appreciate your help but unfortunately the attribute error is still
> called regardless of self.db's state (None or not None).
Maybe we should see some more code (and maybe a traceback) at this
point.
--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308 (800) 735-0555 x308
More information about the Python-list
mailing list