After having successfully build a static data structure (see here), I would want to avoid having to build it from scratch every time a user requests an operation on it. My naïv first idea was to dump the structure (using python's pickle) into a file and load this file for each query. Needless to say (as I figured out), this turns out to ...
Does Pickle always produce the same output for a certain input value? I suppose there could be a gotcha when pickling dictionaries that have the same contents but different insert/delete histories. My goal is to create a "signature" of function arguments, using Pickle and SHA1, for a memoize implementation.
...
I have an object with a CookieJar that I want to pickle.
However as you all probably know, pickle chokes on objects that contain lock objects. And for some horrible reason, a CookieJar has a lock object.
from cPickle import dumps
from cookielib import CookieJar
class Person(object):
def __init__(self, name):
self.name = n...
When trying to pickle the object Inf as defined in numpy (I think), the dumping goes Ok but the loading fails:
>>> cPickle.dump(Inf, file("c:/temp/a.pcl",'wb'))
>>> cPickle.load(file("c:/temp/a.pcl",'rb'))
Traceback (most recent call last):
File "<pyshell#257>", line 1, in <module>
cPickle.load(file("c:/temp/a.pcl",'rb'))
ValueErr...
I'm trying to transfer a transfer a function across a network connection (using asyncore). Is there an easy way to serialize a python function (one that, in this case at least, will have no side affects) for transfer like this?
I would ideally like to have a pair of functions similar to these:
def transmit(func):
obj = pickle.dumps...
I'm trying to make my program faster, so I'm profiling it. Right now the top reason is:
566 1.780 0.003 1.780 0.003 (built-in method decode)
What is this exactly? I never call 'decode' anywhere in my code. It reads text files, but I don't believe they are unicode-encoded.
...
Hi all,
I am considering the use of Quantities to define a number together with its unit. This value most likely will have to be stored on the disk. As you are probably aware, pickling has one major issue: if you relocate the module around, unpickling will not be able to resolve the class, and you will not be able to unpickle the inform...
I am working on my program, GarlicSim, in which a user creates a simulation, then he is able to manipulate it as he desires, and then he can save it to file.
I recently tried implementing the saving feature. The natural thing that occured to me is to pickle the Project object, which contains the entire simulation.
Problem is, the Proje...
(You may read this question for some background)
I would like to have a gracefully-degrading way to pickle objects in Python.
When pickling an object, let's call it the main object, sometimes the Pickler raises an exception because it can't pickle a certain sub-object of the main object. For example, an error I've been getting a lot is...
If a Python 3 class is pickled using protocol 2, it is supposed to work in Python 2, but unfortunately, this fails because the names of some classes have changed.
Assume we have code called as follows.
Sender
pickle.dumps(obj,2)
Receiver
pickle.loads(atom)
To give a specific case, if obj={}, then the error given is:
ImportErr...
From the copy documentation:
Classes can use the same interfaces to control copying that they use to control pickling.
[...]
In order for a class to define its own copy implementation, it can define special methods __copy__() and __deepcopy__()
So which one is it? __setstate__() and __getstate__() that are used when pickl...
I'm trying to write a class for a read-only object which will not be really copied with the copy module, and when it will be pickled to be transferred between processes each process will maintain no more than one copy of it, no matter how many times it will be passed around as a "new" object. Is there already something like that?
...
I have tree structure of widgets e.g. collection contains models and model contains widgets
I wan to copy whole collection, copy.deepcopy is faster in comparison to 'pickle and de-pickle'ing the object but cPickle as being written in C is much faster, so
so why shouldn't I(we) always be using cPickle instead of deepcopy?
Is there any ...
This is the error I got today at filmaster.com:
PicklingError: Can't pickle : it's not the same
object as decimal.Decimal
What does that exactly mean? It does not seem to be making a lot of sense...
It seems to be connected with django caching. You can see the whole traceback here:
Traceback (most recent call last):
Fil...
Given this bug (Python Issue 4892) that gives rise to the following error:
>>> import multiprocessing
>>> multiprocessing.allow_connection_pickling()
>>> q = multiprocessing.Queue()
>>> p = multiprocessing.Pipe()
>>> q.put(p)
>>> q.get()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/.../python2.6/...
The Problem:
I am getting the following traceback and don't understand what it means or how to fix it:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python26\lib\multiprocessing\forking.py", line 342, in main
self = load(from_parent)
File "C:\Python26\lib\pickle.py", line 1370, in load
r...
I'm trying to manually set an object in the Django cache API but it fails (i think due to pickling?)
The object is given to me by a third party, my code is:
def index(request, template_name="mytemplate.htm"):
user_list = cache.get("user_list_ds")
if user_list is None:
# this is the expensive bit I'm trying to cache
...
I'm reading in a file and sending the data (once encrypted) to a dictionary, with a hash of the data before and after encryption. I then pickle the dictionary but find the file size is massive compared to the source file size. If I write the encrypted data straight to a file the size is identical to the source. Any idea why my pickled fi...
Perforce command line has a special switch, -G, that supposedly causes its output to be machine readable, using python's "pickle" serialization format. Is this actually so, in general?
For example, consider the output of p4 -G diff -duw3 <file1> <file2> <file3>. The output, as far as I can tell, is a sequence of: pickle, raw diff, pickl...
Python problem: When I am trying to load sth I dumped using cPickle, I get the error message:
ValueError: insecure string pickle
Both the dumping and loading work are done on the same computer, thus same OS: ubuntu 8.04.
How could I solve this problem?
...