"Timo" <timomli...@gmail.com> wrote

I'm writing an application that stores people with some info. I'm doing this with ConfigParser and it works, but currently (for testing), there are only 10 persons in it. What if I add, let's say, about 500-600 or even more? Is this still a good choice?

I'd be happy with this for up to say 1000 people(arbitrary choice) but
for more than that I'd go with shelve.

So my entry's look like this (more or less ;)):
[person1]
firstName = foo
lastName = bar
father = person2
mother = person3

And I assume you are reading these into a Person class and
storing these classes in a persons dictionary? Then to access
a father becomes:

x = 'Person5'
print Persons[x].father.firstName

Now, I want to make a family tree out of this, something that looks like the following scheme (hope the formating will be kept):

For person "foo bar", on his father-side, and mother-side the same.

                                | father
                | father--<
                |               | mother
person2--<
                |               | father
                | mother--<
                                | mother


You don't necessarily need to store the tree if you only want to display it. Using the Persons dictionary approach you can easily write a function to traverse the tree by following the links to the top of the tree. (Note this
means some people will have to have None as father/mother!)

Similarly you can write a function to find everyone whose father or mother
is X and so on.

For small scale data this is probably easier than building a full tree
structure from your config file. Although that's always an option too
and for larger datasets would be more performant. But then I'd move
to pickle or shelve because you could load/save the whole tree in one
go.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to