static methods

Paul Prescod paulp at ActiveState.com
Sun Mar 25 15:37:43 EST 2001


Marcin 'Qrczak' Kowalczyk wrote:
> 
> Fri, 23 Mar 2001 14:27:42 -0800, Paul Prescod <paulp at ActiveState.com> pisze:
> 
> > 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 :-)

Doh! Okay, it will work if you add it to the instances in the __init__:

class Class:
	def __init__(self):
		self.staticmethod = _static

But the deeper point is that static methods are just a syntactic
short-cut and there are a variety of ways to emulate them...

I can't, off the top of my head, think of any problems with having
Class.methodname return a function object rather than an unbound method.

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.activestate.com/pythoncookbook




More information about the Python-list mailing list