pickle

Unable to unpickle a file on Mac that was pickled on Windows

Hello, I've got a simple class that I am pickling(dumping) to a file. On OS X this works fine, and on Windows this works fine. However, while on windows I can load/unpickle the object fine - when windows then pickles this file and saves it back to disk, it becomes unreadable on OS X (although in Windows it still behaves as normal). Th...

Pickling of one Django model

Can't pickle <class 'authorize.models.User_Deferred_'>: attribute lookup authorize.models.User_Deferred_ failed I get this if use session with db. What this mean? ...

Can't pickle <type 'instancemethod'> when using python's multiprocessing Pool.map()

Hi, I'm trying to use multiprocessing's Pool.map() function to divide out work simultaneously. When I use the following code, it works fine: import multiprocessing def f(x): return x*x def go(): pool = multiprocessing.Pool(processes=4) #result = pool.apply_async(self.f, [10]) #print result.get(timeou...

Is pickle file of python cross-platform?

I have created a small python script of mine. I saved the pickle file on Linux and then used it on windows and then again used it back on Linux but now that file is not working on Linux but it is working perfectly on windows. Is is so that python is coss-platform but the pickle file is not. Is there any solution to this one??? ...

Rails / Cucumber/ Pickle

So in my feature file, I have a login background step: Given /^I login$/ do user = Factory(:user) visit '/login' fill_in("login", :with => user.login) fill_in("password", :with => user.password) click_button("Login") @current_user = user end In the next step, I want to be able to include a user_id, but not sure how to get ...

Pickling a staticmethod in Python

Hello all, I've been trying to pickle an object which contains references to static class methods. Pickle fails (for example on module.MyClass.foo) stating it cannot be pickled, as module.foo does not exist. I have come up with the following solution, using a wrapper object to locate the function upon invocation, saving the container cla...

Singleton python generator? Or, pickle a python generator?

I am using the following code, with nested generators, to iterate over a text document and return training examples using get_train_minibatch(). I would like to persist (pickle) the generators, so I can get back to the same place in the text document. However, you cannot pickle generators. Is there a simple workaround, so that I can sa...

How can I pickle a nested class in python?

I have a nested class: class WidgetType(object): class FloatType(object): pass class TextType(object): pass .. and an oject that refers the nested class type (not an instance of it) like this class ObjectToPickle(object): def __init__(self): self.type = WidgetType.TextType Trying to ser...

Weird unpickling error when using multiprocessing

I get the following error when using multiprocessing: Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner self.run() File "/usr/lib/python2.6/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) File "/usr/lib/python...

Can I store a python dictionary in google's BigTable datastore without serializing it explicitly?

I have a python dictionary that I would like to store in Google's BigTable datastore (it is an attribute in a db.Model class). Is there an easy way to do this? i.e. using a db.DictionaryProperty? Or do I have to use pickle to serialize my dictionary? My dictionary is relatively straight forward. It consists of strings as keys, but it m...

Python - pickling fails for numpy.void objects

>>> idmapfile = open("idmap", mode="w") >>> pickle.dump(idMap, idmapfile) >>> idmapfile.close() >>> idmapfile = open("idmap") >>> unpickled = pickle.load(idmapfile) >>> unpickled == idMap False idMap[1] {1537: (552, 1, 1537, 17.793827056884766, 3), 1540: (4220, 1, 1540, 19.31205940246582, 3), 1544: (592, 1, 1544, ...

Why does this code return 'complex'?

# Example: provide pickling support for complex numbers. try: complex except NameError: pass else: def pickle_complex(c): return complex, (c.real, c.imag) # why return complex here? pickle(complex, pickle_complex, complex) Why? The following code is the pickle function being called: dispatch_table = {} def ...

Best way to save complex Python data structures across program sessions (pickle, json, xml, database, other)

Looking for advice on the best technique for saving complex Python data structures across program sessions. Here's a list of techniques I've come up with so far: pickle/cpickle json jsonpickle xml database (like SQLite) Pickle is the easiest and fastest technique, but my understanding is that there is no guarantee that pickle output...

how to use 'pickle'.

my code(i was unable to use 'pickle'): class A(object): def __getstate__(self): print 'www' return 'sss' def __setstate__(self,d): print 'aaaa' import pickle a = A() s = pickle.dumps(a) e = pickle.loads(s) print s,e print : www aaaa ccopy_reg _reconstructor p0 (c__main__ A p1 c__builtin__ object p2 Nt...

multiprocessing.Process subclass works on Linux but not Windows

Hi, I'm trying to get python-gasp working on Windows, but when I do import gasp; gasp.begin_graphics() I get the following traceback: File "C:\Python26\lib\site-packages\gasp\backend.py", line 142, in create_screen screen.updater.start() File "C:\Python26\lib\multiprocessing\process.py", line 104, in start self._popen = ...

Efficient method to store Python dictionary on disk?

What is the most efficient method to store a Python dictionary on the disk? The only methods I know of right now are plain-text and the pickle module. Edit: Sorry for not being very clear. By efficient I meant fastest execution speed. The dictionary will contain mutable objects that will hold information to be parsed and modified. ...

Saving huge bigram dictionary to file using pickle

a friend of mine wrote this little progam. the textFile is 1.2GB in size (7 years worth of newspapers). He successfully manages to create the dictionary but he cannot write it to a file using pickle(program hangs). import sys import string import cPickle as pickle biGramDict = {} textFile = open(str(sys.argv[1]), 'r') biGramDictFile =...

Question about Cucumber/Pickle

Hi, I'm trying to get a little more familiarity with Rails / ActiveRecord. In trying to do so I am attempting to use Cucumber to help with some "discovery" tests. I have the following Feature: Describing a task In order to work with tasks As a user I want to be able to know what makes up a task and to improve my understanding ...

Accessing Related Model's not yet mentioned

I have a User factory that references a Company Factory.define :user do |f| f.first_name "John" f.last_name "Smith" f.password "test01" f.password_confirmation {|u| u.password} f.email "[email protected]" f.association :company, :factory => :company end Factory.define :company do |f| f.name "My Company" end The Com...

Python pickling after changing a module's directory

I've recently changed my program's directory layout: before, I had all my modules inside the "main" folder. Now, I've moved them into a directory named after the program, and placed an __init__.py there to make a package. Now I have a single .py file in my main directory that is used to launch my program, which is much neater. Anyway, ...