[Tutor] rationale for nested classes?
Kent Johnson
kent37 at tds.net
Mon Aug 17 21:40:02 CEST 2009
On Mon, Aug 17, 2009 at 1:36 PM, Serdar Tumgoren<zstumgoren at gmail.com> wrote:
> Say that I've created a series of Campaign Committee objects from an
> initial data set.
>
> class Committee(object):
> def __init__(self, data):
> self.id = data[0]
> self.name = data[1]
> self.candidate = data[2]
> self.candidateID = data[3]
>
> In the above example, I know for certain that the returned data will
> always have a committee ID. But a number of other data such as the
> name, candidate, and candidateID are often missing or incorrect. So
> after the initialiization of an object, I'm using "self.id" in a
> series of subsequent database queries to correct and/or fill in this
> data.
>
> So my question, in light of Mac's suggestion, is this a case where I
> should add a subclass containing so-called DataIntegrity checks?
I would just create an ordinary fix() method of Committee, e.g.
def fix(self):
self.fix_name()
self.fix_candidate()
self.fix_candidateID()
etc.
Kent
More information about the Tutor
mailing list