[Tutor] yet another question on OO inheritance
Serdar Tumgoren
zstumgoren at gmail.com
Tue Aug 18 20:51:49 CEST 2009
Thanks to you both for the suggestions. I think I'll try the approach
below. But just one follow-up: should I be setting "self.tablename",
or is a static attribute ("tablename") the correct approach?
> A nice way to do this is with a class attribute. For example:
> class Committee(object):
>
> def get_data(self):
> sql = """
> select id, name
> from table_'%(tablename)s'
> """ % {'tablename':self.tablename}
>
> class CandidateCommittee(Committee):
> tablename = 'CandidateTable'
>
> PresidentialCommittee(Committee):
> tablename = 'PresidentialTable'
>
> When you call Committee.get_data() it will get tablename from the
> class of the instance being used.
>
More information about the Tutor
mailing list