Pickling/unpickling extensions types
Martin v. Löwis
martin at v.loewis.de
Thu Sep 11 02:13:24 EDT 2003
Bob <tenorman3 at yahoo.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_unpickling__ 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_arguments)
"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
More information about the Python-list
mailing list