471,579 Members | 1,260 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,579 software developers and data experts.

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 1566

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Andreas Kuntzagk | last post: by
2 posts views Thread by Nick Jacobson | last post: by
6 posts views Thread by Alexander Zatvornitskiy | last post: by
4 posts views Thread by KraftDiner | last post: by
3 posts views Thread by yoma | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

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.