speeding up dictionary creation

Peter Schneider-Kamp nowonder at nowonder.de
Fri Aug 18 00:56:35 EDT 2000


Bob van der Poel wrote:
> 
> Oppps, I probably wasn't clear. The data is read every time the program
> is started up (ie. each time you want to use it). So, anything more than
> a few long seconds is getting unacceptable.

Then make a small script that creates the dict and use
cPickle to dump it to a file. E.g.:

  import cPickle
  dict["foo"] = ...
  dict["spam"] = ...
  ...
  cPickle.dump(dict, open("mydictionary.dump.bin", "wb"), 1)

in your main file you can then use cPickle to load the
dictionary. E.g.:

  import cPickle
  dict = cPickle.load(open("mydictionary.dumb.bin", "rb"), 1)

Let me assure you that cPickle is fast. I am just letting
a few tests run in the background. Results pending.

Peter
-- 
Peter Schneider-Kamp          ++47-7388-7331
Herman Krags veg 51-11        mailto:peter at schneider-kamp.de
N-7050 Trondheim              http://schneider-kamp.de




More information about the Python-list mailing list