folks, what's wrong with this?
robert.kern at gmail.com
Thu Apr 1 15:10:51 EDT 2010
On 2010-04-01 13:56 PM, Ani wrote:
> Hi All:
> I am just a beginner in python. Can anyone please tell me what is
> wrong with this piece of code?
> import copy
> class BaseDummyObject(object):
> def __init__(self):
> def __getattr__(self, item):
> return self.__dict__.__getitem__(item)
> except KeyError:
> print "Attribute Error: attr %s of class %s non-existent!"
You need to raise an AttributeError here. Otherwise, it implicitly returns None
for all attributes not in the __dict__ and thus confusing the copy.deepcopy() code.
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list