static methods

Rick Lee rwklee at home.com
Sat Mar 24 23:39:15 EST 2001


Thanks, and thanks to Alex.  This is very useful, also very telling that it
is pretty obscure.  For me, static, or class-wide methods are very useful.
With this, you only have to pass the class reference to the caller.
Otherwise, you have to pass both the class reference and the module
reference to the caller.

- Rick Lee

"Clark C. Evans" wrote:

> On 24 Mar 2001, Marcin 'Qrczak' Kowalczyk wrote:
> | Fri, 23 Mar 2001 14:27:42 -0800, Paul Prescod <paulp at ActiveState.com>:
> | | Probably because they are simply not neccessary.
> | |
> | | def _static():
> | |     XXX.foo=bar
> | |     return XXX.foo
> | |
> | | class Class:
> | |     staticmethod = _static
> | |     ...
> |
> | It doesn't work. Try to call it.
> |
> | The fact that you are not the first person who thinks it works
> | suggests that the current Python's solution is not ideal :-)
>
> >>> class Class:
>         class StaticFudge:
>             def __call__(self):
>                 print "I am a static"
>         staticmethod = StaticFudge()
> >>> Class.staticmethod()
> I am static
>
>     It took much looking and many wrong answers before
>     Alex Martelli pointed me to this solution.
>

<snip>




More information about the Python-list mailing list