pickle vs .pyc
Gordon McMillan
gmcm at hypernet.com
Wed Jun 2 18:05:01 EDT 1999
Michael Vezie writes:
[saving / loading complex structures]
> The obvious choice is, of course pickle, or some flavor thereof. But
> can someone tell me why this wouldn't be faster:
>
> In the code that does the "pickling", simply do:
> f = open("cache.py", "w")
> f.write("# cache file for fast,slow\n")
> f.write("fast = "+`fast`+'\n')
> f.write("slow = "+`slow'+'\n')
> f.close()
> import cache
>
> Then, later, when I want the data, I just do:
>
> from cache import fast,slow
> Am I missing something here? This sounds like an obvious, and fast,
> way to do things. True, the caching part may take longer. But I
> really don't care about that, since it's done only once, and in the
> background.
Not at all. Where x == eval(repr(x)), this is dandy. You can even use
pprint to dump into a humanly digestible format. You can then edit
and reload.
But marshall should be even faster.
- Gordon
More information about the Python-list
mailing list