471,337 Members | 1,098 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

pickling problem

Hello,

I have a somewhat nested dict that I want to pickle, but it (sometimes) contains some
no-no's (specifically, in this case, functions). I know I can't pickle them, but I
would like to be able to pickle the rest of the dict. Is there a good way to be able
to walk through a dict, and take out all of the non-pickleable objects? I could
replace them with something else (a tag of some sort, for me to reconstruct things
later).
thanks,

Brian Blais

--
-----------------

bb****@bryant.edu
http://web.bryant.edu/~bblais

Jun 7 '07 #1
1 1067

Brian Blais wrote:
Hello,

I have a somewhat nested dict that I want to pickle, but it (sometimes) contains some
no-no's (specifically, in this case, functions). I know I can't pickle them, but I
would like to be able to pickle the rest of the dict. Is there a good way to be able
to walk through a dict, and take out all of the non-pickleable objects? I could
replace them with something else (a tag of some sort, for me to reconstruct things
later).
thanks,

Brian Blais

--
-----------------

bb****@bryant.edu
http://web.bryant.edu/~bblais
One way to do that could be:
>d = {1:functionA, 2:functionB, 3:"String"}
for key in d:
if callable(key): d[key] = "tag"
That would work for the functions in your dictionary.

Jun 8 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

176 posts views Thread by Thomas Reichelt | last post: by
1 post views Thread by Edward Loper | last post: by
8 posts views Thread by Hans Georg Krauthaeuser | last post: by
1 post views Thread by fedor | last post: by
2 posts views Thread by Kirk Strauser | last post: by
reply views Thread by jeanphilippe.aumasson | last post: by
reply views Thread by Irmen de Jong | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.