pickling problem

B

Brian Blais

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
 
P

Pomato

Brian said:
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

--

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top