Implementing deepcopy

Mr.Rech andrea.riciputi at
Wed Dec 7 17:46:02 CET 2005

Hi all,
I'm writing a class with some attributes which deepcopy can't cope
with, and I need some more clarifications. Sorry for my newbie
questions, but I'm a newbie indeed (or a sort of).

Suppose one of the attributes of my class is a dictionary whose values
are callable functions, such as:

>>>def foo():
.....    pass
>>>def bar():
.....    pass

>>>adict = dict(a = foo, b = bar)

Now if I try:

>>> anotherdict = copy.deepcopy(adict)   # It doesn't work


>>> anotherdict = copy.copy(adict)     # works as expected

My question is: anotherdict is really a copy of adict? If so, what is
the difference between its definition and the following:

>>> yanotherdict = dict(adict)


Thanks in advance,

More information about the Python-list mailing list