Dictionary from a file

Hans Nowak hnowak at cuci.nl
Tue Jan 25 16:51:54 EST 2000


On 25 Jan 00, at 10:55, Adrian Eyre wrote:

> > # writeabledict.py
> > """A writeable dictionary."""
> > [snip]
> 
> Isn't this exactly what the 'shelve' module provides?

I've never really used shelve, but AFAIK, the file produced by shelve does
not contain 'readable' code... it looks like it's pickled? Anyway, the
WriteableDict class writes Python-readable code; in fact it exports an
module with a dictionary in it. It's far from perfect; it will not
successfully store class instances, to name something; but in general
cases it works well. (At least for me. :-)

I have one program that uses the WriteableDict principle a lot... an
auxiliary program parses text files and puts the results (Python lists) in
modules. Generating these modules only happens once (well, theoretically
:) ; they are imported by the main program, which is much faster than redo
the parsing every time the program is started, especially when .pyc files
are created.

I found that importing .pyc files is pretty fast. Didn't benchmark it
against shelve/pickle/marshall/etc, though.

--Hans Nowak (zephyrfalcon at hvision.nl)
Homepage: http://fly.to/zephyrfalcon
You call me a masterless man. You are wrong. I am my own master.




More information about the Python-list mailing list