pickle

How to get unpickling to work with iPython?

Hello, I'm trying to load pickled objects in iPython. The error I'm getting is: AttributeError: 'FakeModule' object has no attribute 'World' Anybody know how to get it to work, or at least a workaround for loading objects in iPython in order to interactively browse them? Thanks edited to add: I have a script called world.py th...

Storing complex object on Datastore with Pickle, any faster alternatives?

To store a complex object to Datastore i'm currently using this approach: class PickleProperty(db.Property): data_type = db.Blob def get_value_for_datastore(self, model_instance): value = self.__get__(model_instance, model_instance.__class__) if value is not None: return db.Blob(pickle.dumps(value)) def make_value_f...

related objects in steps with cucumber/pickle

Hi, it would be great if somebody could help me with the cucumber/pickle syntax on creating related objects and assert them. How can I get references in my cucumber syntax... Something Like For example: creating a blog post with a certain title with 3 comments And then assert this post and the related comments... Is this with object ...

Python Pickling Slots Error

I have a large instance that I've been pickling just fine, but recently I started getting this error when I tried to dump it: File "/usr/lib/python2.6/copy_reg.py", line 77, in _reduce_ex raise TypeError("a class that defines __slots__ without " TypeError: a class that defines __slots__ without defining __getstate__ cannot be pick...

Store python classes as pickles in GAE?

Hi, I am porting a Python investing application to Google App Engine. Every market that you can trade in is a plugin: for example the stocks trading and FOREX trading are all plugins. The application stores the portfolio (which is a Portfolio class instance containing the active investments (class instances) and history) as a pickle. H...

Why is this pickled data not unpickling after transfer over a network?

logexample.py logs over the network using logging.handlers.DatagramHandler, which pickles(protocol 1) the data it sends. logserver.py is supposed to unpickle and print to screen, but instead it raises an error. If I use pickle.loads then KeyError: '\x00' and if I use cPickle.loads its an EOFError The files are here - http://gist.github...

How to best pickle/unpickle in class hierarchies if parent and child class instances are pickled

Assume I have a class A and a class B that is derived from A. I want to pickle/unpickle an instance of class B. Both A and B define the _getstate_/_setstate_ methods (Let's assume A and B are complex, which makes the use of _getstate_ and _setstate_ necessary). How should B call the _getstate_/_setstate_ methods of A? My current, but per...

How do I pickle an object?

Here is the code I have: import pickle alist = ['here', 'there'] c = open('config.pck', 'w') pickle.dump(alist, c) and this is the error I receive: Traceback (most recent call last): File "C:\pickle.py", line 1, in ? import pickle File "C:\pickle.py", line 6, in ? pickle.dump(alist, c) AttributeError: 'module' object has no at...

cPickle.UnpicklingError: invalid load key

My program work fine on windows, with cpickle, and I am using binary mode, like 'wb', or 'rb'. When I ran my program on Linux, it still works fine. But when I tried to unpickle the files obtained from the Linux platform on my windows platform, I got this wired message says: cPickle.UnpicklingError: invalid load key' '. Can anyone plea...

Pickle vs output to a file in python

I have a program that outputs some lists that I want to store to work with later. For example, suppose it outputs a list of student names and another list of their midterm scores. I can store this output in the following two ways: Standard File Output way: newFile = open('trialWrite1.py','w') newFile.write(str(firstNames)) newFile.wri...

How do I store then retrieve Python-native data structures into and from a file?

I am reading an XML file and reorganizing the desired data into Python data structures (lists, tuples, etc.) For example, one of my XML parser modules produces the following data: # data_miner.py animals = ['Chicken', 'Sheep', 'Cattle', 'Horse'] population = [150, 200, 50, 30] Then I have a plotter module that roughly says, e.g.: # ...

What does it mean for an object to be picklable (or pickle-able)?

Python docs mention this word a lot and I want to know what it means! Googling doesn't help much.. ...

AttributeError when unpickling an object

I'm trying to pickle an instance of a class in one module, and unpickle it in another. Here's where I pickle: import cPickle def pickleObject(): object = Foo() savefile = open('path/to/file', 'w') cPickle.dump(object, savefile, cPickle.HIGHEST_PROTOCOL) class Foo(object): (...) and here's where I try to unpickle: ...

Help, the insertion cursor moves one line lower each time!

Every time this code is reopened the insertion cursor moves one line lower, how do I stop this? import Tkinter,pickle class Note(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent = parent self.Main() self.load_data() self.protocol("WM_DELETE_WINDOW", self.sa...

Python pickling error when using sessions

In my django app I was creating an extended user profile using session vars. But when registration form was saved and user was about to create, I got following error : Traceback (most recent call last): File "\Python26\Lib\site-packages\django\core\servers\basehttp.py", line 279, in run self.result = application(self.environ, sel...

Is there anything wrong with creating a Python Pickle powered website?

I have been toying with this idea for quite awhile now, but haven't seen any information on people doing it. I have a small website project where I need to load and modify 1 object. This object is pretty simple, and shouldn't be more than a few kb. Instead of running a DB for this small amount of data, why not just use pickle and/or shel...

Serializing IronPython Objects Which Inherit From CLR Types

This may be a bit of a weird question, but is there any reliable way to serialize IronPython objects whose classes extend CLR types? For instance: class Foo(System.Collections.Generic.List[str]): def Test(self): print "test!" System.Collections.Generic.List<string> is serializable with Pickle, as it implements the ISerial...

Cannot put object on Queue

I want to put an instance of scapy.layers.dhcp.BOOTP on a multiprocessing.Queue. Every time I call put() the following exception occures: Traceback (most recent call last): File "/usr/lib/python2.6/multiprocessing/queues.py", line 242, in _feed send(obj) PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.f...

How to pickle and unpickle instances of a class that inherits from defaultdict?

I have a class that inherits from defaultdict like this: class listdict(defaultdict): def __init__(self): defaultdict.__init__(self, list) I can pickle it, but when I unpickle it, this happens: ('__init__() takes exactly 1 argument (2 given)', <class 'listdict'>, (<type 'list'>,)) The class does not define any special m...

Pickling objects

I need to pickle object [wxpython frame object] and send it as a prameter to this function apply_async on multiproccessing pool module could someone provide me an example how can I do it I tried the following and get an error message : myfile = file(r"C:\binary.dat", "w") pickle.dump(self, myfile) myfile.close() self.my_pool.apply_a...