[Python-Dev] method decorators (PEP 318)
Dave Harrison
dave at nullcube.com
Sun Mar 28 23:49:48 EST 2004
> > > and wouldn't bother with staticmethods at all. How often do you
> > > actually need a staticmethod in particular and *not* a classmethod?
> >
> > It's quite useful to be able to develop, essentially stateless, static
> > method utility libraries that dont need to be class based. Why create
>
> I'm not sure I understand. Why not make them module-level functions?
Let me give an example. Lets say I want to do a generic transformation
of a dict, like reversing the key and value positions
a = {'a':1, 'b':2}
and I want to invert it to
b = {1:'a', 2:'b'}
using my function invert()
That's generic enough that I could use it in heaps of places, but I dont
want to have to either put it in an object, or cut and paste the code
across, so as you say, I have a utility module, but it doesn't need to
be a class (I understood from your email that all functions would
require a class item with your suggested syntax - as below).
> def foo(class cls, x, y)
Example isn't fantastic *shrug*, but there are time when you have
something you need to do in a bunch of places, it's not in the current
libraries, and you don't need it to be a in a class.
It might be that I've missed the point entirely, and that you were only
referring to methods within a class. In which case I'll be quiet ;-)
In fact in re-reading your mail, that might be the case entirely
*chuckle*
--
Dave Harrison
Nullcube
dave at nullcube.com
http://www.nullcube.com
More information about the Python-Dev
mailing list