[Tutor] copy(): another 'str' object is not callable???
Don Arnold
Don Arnold" <darnold02@sprynet.com
Thu May 1 22:24:02 2003
----- Original Message -----
From: <pan@uchicago.edu>
To: <tutor@python.org>
Sent: Thursday, May 01, 2003 8:32 PM
Subject: Re: [Tutor] copy(): another 'str' object is not callable???
> Ok folks, here's another "'str' object is not callable" question.
> This time it happens in the copy module. See below:
>
>
> '''
> >>> class aclass:
> ... def __init__(self): self.aValue='a value'
> ... def __getattr__(self, name):
> ... return self.aValue
> ... def copy(self):
> ... return copy.deepcopy(self)
> ...
> >>> a = aclass()
> >>> b = a.copy()
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> File "<interactive input>", line 10, in copy
> File "E:\Program Files\prog\lang\py\ActivePython\lib\copy.py", line
179,
> in deepcopy
> y = copierfunction(x, memo)
> File "E:\Program Files\prog\lang\py\ActivePython\lib\copy.py", line
262,
> in _deepcopy_inst
> return x.__deepcopy__(memo)
> TypeError: 'str' object is not callable
> '''
>
> What's wrong with the above code?
>
> I did a little test and found, again, that this error came
> from the '__getattr__'. If it is removed then the copy function
> works.
>
> any help is appreciated.
> pan
This is the same problem you had before. By overriding __getattr__, the
lookup for the object's print method returns a string, which isn't callable.
HTH,
Don