[Tutor] copy(): another 'str' object is not callable???

pan@uchicago.edu pan@uchicago.edu
Thu May 1 21:33:01 2003


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