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?
thanks
gong 4 2528
"gong" <go****@cutey.c om> wrote in message
news:9a******** *************** ***@posting.goo gle.com... 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?
thanks gong
Why do you want to do this? According to the docs, all that
is saved for a function or a class is the name. Code, data and
so forth is not saved, so it makes no sense to try to pickle
a lambda unless you've bound it to a name at the module
level. See 3.14.4 (Python 2.3.3 Library Reference.)
If you really want to serialize a function's code, look at
the marshal module.
John Roth go****@cutey.co m (gong) writes: 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 (?)
Yes.
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
[...]
No, read it again. What you found was Guido figuring out how to
*prevent* people pickling lambdas. Functions are pickled by saving
the function name. Lambdas have no function name, so pickle complains
if you try to pickle them.
John
"John Roth" <ne********@jhr othjr.com> writes: 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?
Why do you want to do this? According to the docs, all that is saved for a function or a class is the name. Code, data and so forth is not saved, so it makes no sense to try to pickle a lambda unless you've bound it to a name at the module level.
I think the idea may be to pickle a closure, to save the data inside
it. I do remember some mention about pickling generators. Anyway, in
Python 2.x the closest you can come to that is pickling class
instances.
"Paul Rubin" <http://ph****@NOSPAM.i nvalid> wrote in message
news:7x******** ****@ruckus.bro uhaha.com... "John Roth" <ne********@jhr othjr.com> writes: 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?
Why do you want to do this? According to the docs, all that is saved for a function or a class is the name. Code, data and so forth is not saved, so it makes no sense to try to pickle a lambda unless you've bound it to a name at the module level.
I think the idea may be to pickle a closure, to save the data inside it. I do remember some mention about pickling generators. Anyway, in Python 2.x the closest you can come to that is pickling class instances.
That ought to work as long as you unpickle it into the same module
so you can get the original class definition.
John Roth This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
|
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
|
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'))
|
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.
|
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
| |
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')
|
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
|
by: jeanphilippe.aumasson |
last post by:
Hi,
I have some problems when pickling an instance of a class, i don't
retrieve all its attributes instances after loading. I'm quite a
beginner in Python, so it may be a stupid error... Here the full
description :
I have a class Test, having an attribute self.problem, as an instance
of Problem class, defined in the same module.
Problem as an attribute self.optimum, that is a list of Point
|
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):
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |