473,734 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can't pickle instancemethod objects

Pickling an instance of a class, gives "can't pickle instancemethod
objects". What does this mean? How do I find the class method creating
the problem?

Jul 9 '06 #1
6 12344
On Sun, 09 Jul 2006 05:45:27 -0700, Jim Lewis wrote:
Pickling an instance of a class, gives "can't pickle instancemethod
objects". What does this mean?
It means you can't pickle instance methods.
How do I find the class method creating the problem?
How about you post the complete stack trace of the exception? Chances are
it will contain much useful information.
--
Steven.

Jul 9 '06 #2
How about you post the complete stack trace of the exception?

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\program files\python\li b\lib-tk\Tkinter.py", line 1345, in
__call__
return self.func(*args )
File "C:\Public\worl d.py", line 1832, in BtnGo
DoBtnGo()
File "C:\Public\worl d.py", line 1812, in DoBtnGo
if DoPickle: SavePickle ()
File "C:\Public\worl d.py", line 1817, in SavePickle
pickle.dump (pop,f)
File "C:\program files\python\li b\pickle.py", line 1382, in dump
Pickler(file, protocol, bin).dump(obj)
File "C:\program files\python\li b\pickle.py", line 231, in dump
self.save(obj)
File "C:\program files\python\li b\pickle.py", line 293, in save
f(self, obj) # Call unbound method with explicit self
File "C:\program files\python\li b\pickle.py", line 739, in save_inst
save(stuff)
File "C:\program files\python\li b\pickle.py", line 293, in save
f(self, obj) # Call unbound method with explicit self
File "C:\program files\python\li b\pickle.py", line 663, in save_dict
self._batch_set items(obj.iteri tems())
File "C:\program files\python\li b\pickle.py", line 677, in
_batch_setitems
save(v)
File "C:\program files\python\li b\pickle.py", line 293, in save
f(self, obj) # Call unbound method with explicit self
File "C:\program files\python\li b\pickle.py", line 614, in save_list
self._batch_app ends(iter(obj))
File "C:\program files\python\li b\pickle.py", line 629, in
_batch_appends
save(x)
File "C:\program files\python\li b\pickle.py", line 293, in save
f(self, obj) # Call unbound method with explicit self
File "C:\program files\python\li b\pickle.py", line 739, in save_inst
save(stuff)
File "C:\program files\python\li b\pickle.py", line 293, in save
f(self, obj) # Call unbound method with explicit self
File "C:\program files\python\li b\pickle.py", line 663, in save_dict
self._batch_set items(obj.iteri tems())
File "C:\program files\python\li b\pickle.py", line 677, in
_batch_setitems
save(v)
File "C:\program files\python\li b\pickle.py", line 313, in save
rv = reduce(self.pro to)
File "C:\program files\python\li b\copy_reg.py", line 69, in
_reduce_ex
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle instancemethod objects

Jul 9 '06 #3
On Sun, 09 Jul 2006 07:06:25 -0700, Jim Lewis wrote:
>How about you post the complete stack trace of the exception?

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\program files\python\li b\lib-tk\Tkinter.py", line 1345, in
__call__
return self.func(*args )
File "C:\Public\worl d.py", line 1832, in BtnGo
DoBtnGo()
File "C:\Public\worl d.py", line 1812, in DoBtnGo
if DoPickle: SavePickle ()
File "C:\Public\worl d.py", line 1817, in SavePickle
pickle.dump (pop,f)
I'd suggest that "pop" could be your culprit. At least, that's where I'd
start looking. What is pop? A function or an instance method?

I can't reproduce your error exactly -- the closest I get is "TypeError:
can't pickle function objects" when I try to pickle a method. Possibly
that's just a change in error message, which is not guaranteed to be
constant across Python versions.

--
Steven.

Jul 9 '06 #4
I'd suggest that "pop" could be your culprit. ...What is pop? A function or an instance method?

Neither. pop is an instance of a class, like:
class X:
...
pop = X ()

pop surely is the culprit but it has arrays of objects, etc., and I
don't know what to look for.

Jul 9 '06 #5
On Sun, 09 Jul 2006 08:39:29 -0700, Jim Lewis wrote:
>I'd suggest that "pop" could be your culprit. ...What is pop? A function or an instance method?

Neither. pop is an instance of a class, like:
class X:
...
pop = X ()

pop surely is the culprit but it has arrays of objects, etc., and I
don't know what to look for.
I'd start by looking for an attribute of pop that holds a reference to
some function or method. E.g. something like this:

class X():
def method(self):
pass
def __init__(self):
self.L = [1, "a", X.method] # note the lack of ()s

pop = X()

Otherwise, I'm working blind without knowing more about your class.

Here's a thought: comment out every attribute in your class, and then try
pickling it. If it succeeds, uncomment just *one* attribute, and try
pickling again. Repeat until pickling fails.
--
Steven.

Jul 9 '06 #6
Here's a thought: comment out every attribute in your class, and then try
pickling it. If it succeeds, uncomment just *one* attribute, and try
pickling again. Repeat until pickling fails.
Was trying to avoid that but you motivated me to do so and now I found
the probem.

In a utility routine I had:
obj.act = act
ActionSucceded = obj.act()

Had to add:
obj.act = None

Thanks :-)

Jul 9 '06 #7

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

Similar topics

2
9846
by: Jane Austine | last post by:
Hi. class A: def __init__(self,tick): if tick: self.foo=self.bar else: self.foo=self.bur def bar(self): print 'bar'
3
11519
by: Guy Lateur | last post by:
Hi all, I've been writing an application containing a lot of settings which can be changed by the user. I'm using wx.Config to read/write these settings (to the windows registry). This means I can only store strings, ints and floats. However, it would be very convenient if I could also store more general objects. It seems to work for wx.Colour, but not for wx.Font. It raises a "TypeError: can't pickle PySwigObject objects".
8
2026
by: Murali Inguva | last post by:
Hi Guys, Couple Questions 1. Is there any way that i can pass client Side Objects to Server Side. 2. Can i validate the data of serverside text boxes / combo box in client side? If you know the answers please let me know. Thanks
24
3631
by: rdc02271 | last post by:
Hello! Is this too crazy or not? Copy constructor: why can't I copy objects as if they were structs? I have a set of simple objects (no string properties, just integers, doubles) and I have to copy the same object millions of times. So instead of writing in the copy constructor property1=SourceObject.property1 can't I use memory copy functions to do this faster? Is this too stupid? By the way, I'm a C++ newbie! But don't go easy on me...
2
3539
by: Michele Simionato | last post by:
Can somebody explain what's happening with the following script? $ echo example.py import pickle class Example(object): def __init__(self, obj, registry): self._obj = obj self._registry = registry
10
7778
by: est | last post by:
>>import md5 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python25\lib\pickle.py", line 1366, in dumps Pickler(file, protocol).dump(obj) File "C:\Python25\lib\pickle.py", line 224, in dump self.save(obj) File "C:\Python25\lib\pickle.py", line 306, in save rv = reduce(self.proto) File "C:\Python25\lib\copy_reg.py", line 69, in _reduce_ex
1
6347
by: IceMan85 | last post by:
Hi to all, I have spent the whole morning trying, with no success to pickle an object that I have created. The error that I get is : Can't pickle 'SRE_Match' object: <_sre.SRE_Match object at 0x2a969c0ad0> the complete stack is the following : Traceback (most recent call last): File "manager.py", line 305, in ? commandLineExec (log, parser) File "manager.py", line 229, in commandLineExec
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
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
9236
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
8186
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...
0
4550
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
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
2724
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.