Le Wed, 4 Feb 2009 01:16:17 +0000 (GMT),
ALAN GAULD <[email protected]> a écrit :
> > > And I assume you are reading these into a Person class and
> > > storing these classes in a persons dictionary?
>
>
> > Can you explain this a little more for me please?
>
>
> Sure.
> (I didn't notice this on gmane so apologies if others already answered)
>
> > The current way of reading the data is this:
> >
> > parser = ConfigParser.ConfigParser()
> > parser.read(personFile)
> >
> > def get_info(person)
> > infoDic = {}
> > infoDic['first'] = parser.get(person, 'firstName')
> > infoDic['last'] = parser.get(person, 'lastName')
> > infoDic['father'] = parser.get(person, 'father')
> > infoDic['mother'] = parser.get(person, 'mother')
> > return infoDic
>
> TYhis is almost the same but you are using a dict. A sligtly more readable
> version is to define a class Person:
>
> class Person:
> def __init__(self, parser):
> self.first = parser.get(person, 'firstName')
> self.last = parser.get(person, 'lastName')
> self.father = parser.get(person, 'father')
> self.mother = parser.get(person, 'mother')
>
Maybe I don't get the point, but I find it strange to make Person dependant not
only of the data storage format, but also of the parsing technique. I would
have written __init__ as usual so as to require the parser to deliver proper
information -- not the contrary:
class Person:
def __init__(self, first, last, father, mother):
self.first = first
self.last = last
self.father = father
self.mother = mother
If the format evoluates --> adapt the parser
If the parser changes --> adapt it to Person's interface
But the Person model has its own meaning. It should change only if the
application's specification evoluates.
Denis
------
la vida e estranya
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor