static methods
Clark C. Evans
cce at clarkevans.com
Sat Mar 24 18:07:32 EST 2001
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.
| | This proposal asks that None be allowed when calling a
| | method using the class syntax, e.g., the following
| | syntax would be allowed, MyClass.method(None,...).
|
| I would be more radical and allow anything as the first argument.
| In other words, don't touch function objects while retrieving them
| from a class. Instead, convert them to bound methods when retrieving
| them from an instance.
This was my initial position
| The only problem seems that some errors will be poorly detected.
This is why I reduced it to only allowing "None".
;) Clark
More information about the Python-list
mailing list