static methods and meta classes
Nick Perkins
nperkins7 at home.com
Fri Jul 13 18:01:15 EDT 2001
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52304
"Rod Mancisidor" <rmancisidor at austin.rr.com> wrote in message
news:nIJ37.79679$WT.15186091 at typhoon.austin.rr.com...
> For reasons that are a bit complicated to explain I have developed a
program
> that passes classes around quite a bit as parameters. I now need to
> associate methods that can be invoked on the class objects themselves as
> opposed to the instances of the class. As an example, for a given class:
>
> class Foo:
> def f(self, param): return param + 1
>
> I need to invoke Foo.f(10). This obviously won't work given that f is not
a
> static method. So I thought I could to this:
>
> class MetaFoo:
> def f(self, param): return param + 1
>
> class Foo:
> __class__ = MetaFoo
>
> In the hope that python could think of Foo as a class that is also an
> instance of MetaFoo and allow me to invoke:
>
> Foo.f(10)
>
> This does not work. I wonder why, every other undocumented crazy thing I
> have tried in Python works. Does anyone know how to trick Python into
> supporting static methods?
>
> If you have a reply and can also send it to rod at mancisidor.com I would
> appreciate it.
>
> Thanks
>
>
>
>
More information about the Python-list
mailing list