[Tutor] (de)serialization questions

Alan Gauld alan.gauld at btinternet.com
Sat Oct 2 03:01:40 CEST 2010


"Albert-Jan Roskam" <fomcl at yahoo.com> wrote

> Maybe my main question is as follows: what permanent object is most 
> suitable to
> store a large amount of entries (maybe too many to fit into the 
> computer's
> memory), which can be looked up very fast.

It depends on the nature of the object and the lookup but in general
a database would be the best solution. For special (heirarchical)
data an LDAP directory may be more appropriate.

Otherwise you are looking at a custom designed file structure.

> Eventually, I want to create two objects:
> 1-one to look up street name and city using zip code
> 2-one to look up zip code using street name, apartment number and 
> city

For this a simple relational database wouldbe best.
SQLlite should do and is part of the standard library.
It can also be used in memory for faster speed with smaller data sets.

> You suggest to simply use a file. I like simple solutions, but 
> doesn't that, by
> definition, require a slow, linear search?

No, you can use random access provided yopu can relate the key to the
location - thats what databases do for you under the covers.

> Funny you should mention sqlite: I was just considering it 
> yesterday. Gosh,
> Python has so much interesting stuff to offer!

Sqlite operating in-memory would be a good solution for you I think.

You can get a basic tutorial on Sqllite and python in the databases 
topic
of my tutorial...

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list