Going the PL/1 way

Robin Becker robin at reportlab.com
Mon Aug 9 06:18:30 EDT 2004


Christian Tismer wrote:

.......
> 
> Trying to call func via an instance also doesn't work:
> 
>  >>> inst = MyClass()
>  >>> inst.func(2, 3)
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> TypeError: func() takes exactly 2 arguments (3 given)
>  >>>
> 
> Now, with the mentioned extra line, the function object is
> modified in a way that it understands that it is an ordinary
> function, and it works in both cases:
> 
>  >>> class MyClass(object):
> ...     def func(arg1, arg2):
> ...         return arg1 + arg2
> ...     func=staticmethod(func)
> ...    
>  >>> MyClass.func(2, 3)
> 5
>  >>> inst = MyClass()
>  >>> inst.func(2, 3)
> 5
>  >>>
> 

Isn't robustness an issue with the @ decorator as well? The most important 
symbol can be omitted without causing a syntax error, but I suppose the same can 
be argued for any of the unary operations.
-- 
Robin Becker



More information about the Python-list mailing list