473,473 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Lambda with copy.deepcopy()

Howdy --

I have a class that has an attribute that is a dictionary that contains
an object that has a kword argument that is a lambda. Confused yet?
Simplified example:

import copy

class Foo:
def __init__(self, fn=None):
self.fn = fn

class Bar:
d = {'foobar': Foo(fn=lambda x: x*x)}

def cp(self):
self.xerox = copy.deepcopy(self.d)

When I execute:

b = Bar()
b.cp()

Using Python version:

Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin

I get:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 5, in cp
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/copy.py", line 179, in deepcopy
y = copier(x, memo)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/copy.py", line 270, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/copy.py", line 179, in deepcopy
y = copier(x, memo)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/copy.py", line 307, in _deepcopy_inst
state = deepcopy(state, memo)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/copy.py", line 179, in deepcopy
y = copier(x, memo)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/copy.py", line 270, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/copy.py", line 206, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/copy.py", line 338, in _reconstruct
y = callable(*args)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/copy_reg.py", line 92, in __newobj__
return cls.__new__(cls, *args)
TypeError: function() takes at least 2 arguments (0 given)

I've googled for deepcopy and lambda and found somebody else asking the
same question on a LUG somewhere, but they gave no advice and nobody
else seems to have run into this. Any ideas on what the problem is/how
to get around it? Thanks!

-jag

Aug 30 '05 #1
0 1664

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

Similar topics

2
by: Andreas Kuntzagk | last post by:
Hi, There are three ways to (shallow)copy a list l I'm aware of: >>> l2=list(l) >>> l2=l >>> l2.copy.copy(l) Are there any differences? Are there more (reasonable) ways? I think the first...
2
by: Nick Jacobson | last post by:
This question is with regard to the * operator as used for sequence concatenation. There's the well-known gotcha: a = ] b = a*3 b = 4 print b
6
by: Alexander Zatvornitskiy | last post by:
Hello! I have trouble with copy/deepcopy. It seems, I just don't understand something. Please explain where things goes wrong and how to do it the right way. I have one class: class...
2
by: Alex | last post by:
Entering the following in the Python shell yields >>> help(dict.copy) Help on method_descriptor: copy(...) D.copy() -> a shallow copy of D >>>
4
by: KraftDiner | last post by:
I'm having trouble getting a copy of and object... (a deep copy) I'm writing a method that creates a mirror image of an object (on screen) In order to do this i need to get a copy of the object...
28
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are...
4
by: Emin | last post by:
Dear experts, I got some unexpected behavior in getattr and copy.deepcopy (see transcript below). I'm not sure if this is actually a bug in copy.deepcopy or if I'm doing something too magical...
0
bartonc
by: bartonc | last post by:
I was playing around with the Simple Metaclassing thread and found something odd: >>> class aClass: ... classVar1 = 'hello' ... def __init__(self, arg1): ... self.instVar1 = arg1...
3
by: yoma | last post by:
python version 2.5 in module copy we all know that copy have two method: copy() and deepcopy(). and the explain is - A shallow copy constructs a new compound object and then (to the extent...
0
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,...
0
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,...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.