confusion about __getattr__
Quinn Dunkan
quinn at upchuck.ugcs.caltech.edu
Thu Jan 17 03:13:07 EST 2002
On Wed, 16 Jan 2002 21:47:37 -0500, Russ Cox <rsc at plan9.bell-labs.com> wrote:
>Could someone explain the error message in the
>following to me? I apologize if it should be
>obvious, but clearly I have the wrong mental
>picture of what's going on.
>
>g% python
>Python 2.2+ (#0, Jan 16 2002, 19:28:19) [C] on unknown
>Type "help", "copyright", "credits" or "license" for more information.
>>>> class Test:
>... def __getattr__(self, name):
>... return '__getattr__ for '+name
>... def __init__(self):
>... self.foo = 'bar'
>... def asdf(self):
>... return 'jkl;'
>...
>>>> t=Test()
>>>> t.foo
>'bar'
>>>> t.sdfsdfdsf
>'__getattr__ for sdfsdfdsf'
>>>> t.asdf()
>'jkl;'
>>>> t.asdf
>Traceback (most recent call last):
> File "<stdin>", line 1, in ?
>TypeError: 'str' object is not callable
>>>>
>
>What is the str object in question that isn't callable?
>
>Thanks.
>Russ
>
More information about the Python-list
mailing list