Static class methods

Michael Hudson mwh21 at cam.ac.uk
Mon Mar 5 15:13:20 EST 2001


"Alex Shindich" <alex at shindich.com> writes:

> Just out of my curiosity, have any of you ladies and gentlemen
> experienced a need for an equivalent of C++/Java static method?

Here's a particularly nasty way to do what you want.

class C:
    class _Temp:
        def __call__(self, arg):
            print arg
    static = _Temp()
    del _Temp

    def call_static(self):
        self.static("from meth")

Then:

>>> C.static("from cli")
from cli
>>> C().static("from cli 2")
from cli 2
>>> C().call_static()
from meth

Cheers,
M.

-- 
  There are two kinds of large software systems: those that evolved
  from small systems and those that don't work.
                           -- Seen on slashdot.org, then quoted by amk



More information about the Python-list mailing list