[Tutor] More on Pickle
Hugo González Monteverde
hugonz-lists at h-lab.net
Thu Mar 2 17:22:52 CET 2006
Make sure you hit Reply-all in your mail program, so the whole list can
get the message. I'm forwarding for visibility anyway.
>Thank you for your response, but now i have more
>the file must exist before that, or it can be created
>at the same time I do the call to sabe de dictionary?
It is created in the call to the open() function, with parameter "w"
>I have two dictionaries like this:
>one to save the type of the variables I save, and it
>is indexed by the name of the variable
The data is not contained in any variable until you unpickle it and
>what i want to do is sth like that:
>save (dictionaries, file)
>so in the file I want to save the 2 dictionaries, and
>later, load the two dictionaris. Is it possible?Is it
>possible to have both dictionaries in the same file?
Yes, you use Pickle.dump() for the same file, one var after the other.
When you unpickle it, do it from the last var you pickled..
fileo = open("mypickle", "w")
then when unpickling
myvar2 = cPickle.load(mypickle)
myvar = cPickle.load(mypickle)
Note the order.... and you don't have to do any seeking in the file or
Looks to me that you should try some more in the interactive prompt;
that's how one discovers if it works.
Hope that helps, give it a shot, remember you can do some tries without
incorporating it in your main progran, just to see how it works.
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
More information about the Tutor