[Tutor] yet another question on OO inheritance
Serdar Tumgoren
zstumgoren at gmail.com
Tue Aug 18 22:44:33 CEST 2009
> ..The atttribute is created in the class definition
> (not in any method) as just "tablename". This creates an attribute of
> the class, rather than of the instance. It is accessed as
> "self.tablename". The attribute lookup rules will look first in the
> instance, fail to find 'tablename', then look in the class and find
> it.
Aha! A very smart solution indeed. I initially had errors with this
approach because I was continuing to define "table" inside of
__init__:
class Derived(Base):
def __init__(self):
table = "TableName"
But as you suggested, moving the table name outside of the constructor
method (__init__) resolved the situation:
class Derived(Base):
table = "TableName"
def __init__(self):
#etc...
As always, many many thanks!!
Regards,
Serdar
More information about the Tutor
mailing list