473,785 Members | 2,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pickling/unpickling extensions types

Bob
I've read over section 3.14.5.2 of the doc about a
zillion times, and it still makes absolutely no sense
to me. Can someone please explain it?

What I'd like to do is, basically, have the object be
pickled as None, since it represents an object in the
C world, and it doesn't make sense to pickle it at
all. How can I do that, if at all?

In particular, what does this

"A callable object, which in the unpickling
environment must be either a class, a callable
registered as a ``safe constructor'' (see below), or
it must have an attribute __safe_for_unpi ckling__ with
a true value. Otherwise, an UnpicklingError will be
raised in the unpickling environment. Note that as
usual, the callable itself is pickled by name"

mean?

_______________ _______________ ____
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Jul 18 '05 #1
1 1738
Bob <te*******@yaho o.com> writes:
In particular, what does this

"A callable object, which in the unpickling
environment must be either a class, a callable
registered as a ``safe constructor'' (see below), or
it must have an attribute __safe_for_unpi ckling__ with
a true value. Otherwise, an UnpicklingError will be
raised in the unpickling environment. Note that as
usual, the callable itself is pickled by name"

mean?


What part of it is it that you don't understand? A "callable object"
is one that you can call. E.g. X is callable, if X(some_argument s)
"works":
1() Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'int' object is not callable id(id)

1076510860

So the builtin id is callable, the number 1 is not. Examples for
callable objects are functions, bound methods, classes, and objects
whose classes implement __call__.

For "safe constructors", see below in the text.

"Have an attribute" means that getattr works. An object X has an
attribute y if X.y "works".

Regards,
Martin
Jul 18 '05 #2

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

Similar topics

1
1532
by: Thomas Guettler | last post by:
Hi! After unpickling the objects are not the same any more. Is this a bug or feature? import pickle class MyDictContainer(dict): def __init__(self): dict.__init__(self)
1
2332
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.
0
1404
by: Skip Montanaro | last post by:
I have a class that inherits from PyGTK's gobject.GObject. I thought to pickle it I'd be able to just define __etstate__ methods. When I attempt to dump an instance of this class I get a TypeError from copy_reg._reduce_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
0
1165
by: benevilent | last post by:
Hey, I am creating an extension type in C for Python, which I want it such that instances can be pickled. I basically want the functionality of the 'object' type such that subclasses of the type which I define, can define methods including __getstate__ which will get called on pickling/unpickling. To do this I need to define the __reduce__ method. The __reduce__ method in typeobject.c is exactly what I need for this task. Is there a...
1
3261
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
1
2280
by: Erik Max Francis | last post by:
I've come across a limitation in unpickling certain types of complex data structures which involve instances that override __hash__, and was wondering if it was known (basic searches didn't seem to come up with anything similar) and if there is a workaround for it short of restructuring the data structures in question. The fundamental issue rests with defining classes which override __cmp__ and __hash__ in order to be used as keys in...
0
1277
by: Shahin Saadati | last post by:
Hi, The following sample code is to pickle and unpickle an object. It works fine with CPython, but the unpickling fails in Jython and I receive an error stating that "A" is unsafe to unpickle (even though I believe I have the code to make "A" safe for unpickling). What do I do wrong and how can I fix it? Thanks, ============================================== import sys
9
3602
by: Alex | last post by:
I have a serious problem and I hope there is some solution. It is easier to illustrate with a simple code: >>> class Parent(object): __slots__= def __init__(self, a, b): self.A=a; self.B=b def __getstate__(self): return self.A, self.B def __setstate__(self, tup):
3
3611
by: sushant.sirsikar | last post by:
Hi, I am new in Python World.I want to know what is mean by ``pickling'' and ``unpickling'' ? And how can we used it?Please Give Me some links of Picking Examples. Thanks Sushant
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10350
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
10157
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...
0
9957
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8983
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
6742
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
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.