473,796 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pickling sublcass of gobject.GObject ?


I have a class that inherits from PyGTK's gobject.GObject . I thought to
pickle it I'd be able to just define __[gs]etstate__ methods. When I
attempt to dump an instance of this class I get a TypeError from
copy_reg._reduc e_ex telling me that GObject.__init_ _() takes no args but
that it was called with one arg. Here's a "hello world" example:

#!/usr/bin/env python

import pickle

import gobject

class C(gobject.GObje ct):
def __init__(self):
self.__gobject_ init__()
self.x = 5

def __getstate__(se lf):
return (self.x,)

def __setstate__(se lf, state):
self.x = state[0]

c = C()
print pickle.dumps(c)

and the output I get when I run it:

% python pickletst.py
Traceback (most recent call last):
File "pickletst. py", line 19, in ?
print pickle.dumps(c)
File "/opt/lang/python-2.3.4/lib/python2.3/pickle.py", line 1386, in dumps
Pickler(file, protocol, bin).dump(obj)
File "/opt/lang/python-2.3.4/lib/python2.3/pickle.py", line 231, in dump
self.save(obj)
File "/opt/lang/python-2.3.4/lib/python2.3/pickle.py", line 313, in save
rv = reduce(self.pro to)
File "/opt/lang/python-2.3.4/lib/python2.3/copy_reg.py", line 70, in _reduce_ex
state = base(self)
TypeError: GObject.__init_ _() takes exactly 0 arguments (1 given)

Thinking that since my class is a subclass of an extension class I might
have to provide a __reduce__ method, I read about it in the Pickle docs
("Pickling and unpickling extension types"), but I found the description of
what it's supposed to return completely incomprehensibl e. If someone can
provide me with a simple example, I will be happy to update that section of
the docs.

Thx,

Skip

Jul 18 '05 #1
0 1404

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2528
by: gong | last post by:
hi i would like to pickle a lambda; according to the library docs in 2.3, i believe this shouldnt be possible, since a lambda is not a function defined at the top level of a module (?) however, upon google searching for "python lambda pickle" i find 2 posts, one including gvr, which apparently demonstrate that this was being attempted and even suggest that it is feasible. has this become available yet, or will it be soon?
1
2333
by: Marc | last post by:
Hi all, After some research I've decided that my previous question (Confusing problem between Tkinter.Intvar...) was headed in the wrong direction. Partly because I think I have a greater understanding of what was happening, and partly because pickling Tkinter widgets is an issue that seems to have been touched on over the years but never really acted on. Postings back to '96 have talked about the need to pickle Tk widgets.
176
8194
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? Thank you, -- greetz tom
1
2298
by: Edward Loper | last post by:
I'm having trouble pickling subclasses of dict when they contain cycles. In particular: >>> import pickle >>> class D(dict): pass >>> d = D() >>> d = d # add a cycle. >>> print d {1: {...}} >>> pickle.dump(d, open('d.pickle', 'w'))
8
8124
by: Hans Georg Krauthaeuser | last post by:
Dear all, I have a long running application (electromagnetic compatibility measurements in mode-stirred chambers over GPIB) that use pickle (cPickle) to autosave a class instance with all the measured data from time to time. At the beginning, pickling is quite fast but when the data becomes more and more pickling slows down rapidly.
1
3262
by: fedor | last post by:
Hi all, happy new year, I was trying to pickle a instance of a subclass of a tuple when I ran into a problem. Pickling doesn't work with HIGHEST_PROTOCOL. How should I rewrite my class so I can pickle it? Thanks , Fedor
2
2257
by: Kirk Strauser | last post by:
I have a module that defines a Search class and a SearchResult class. I use these classes by writing other modules that subclass both of them as needed to interface with particular search engines. My problem is that Search defines a method (called automatically by __del__) to save its results between invocations: def _saveresults(self): self._oldresults = self._results file = open(self._storefile(), 'w')
0
1410
by: jkn | last post by:
Hi all this is my first go at pickling and I'm having trouble with variables of type VT_DATE returned from a COM application. I don't seem to be successfully pickling/depickling to the the same value. I think this may be due to a strange return value. The VT_DATE seems to be a floating point number 'days.(hours, seconds) since midnight 30 December 1899'. in some cases I get a value (probably 0.0?) which is printed as
0
1390
by: Irmen de Jong | last post by:
I'm having troubles pickling classes that extend Exception. Given the following source: class Foo(object): def __init__(self, m): self.m=m class Bar(Exception): def __init__(self, m):
0
10237
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10187
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.