staticmethod() problems

Michele Simionato mis6 at
Thu Jan 23 21:30:12 CET 2003

Aum <spam-me at> wrote in message news:<YMRX9.43233$F63.924790 at>...
> But there's a real problem with staticmethod. Within a staticmethod 
> function, I can't see any way to access other static attributes of the 
> class - methods or attributes - without knowing the class' name.
> With this restriction, python's static method implementation falls short of 
> that of C++ (I won't say j--- because I don't know j---). At least in C++, 
> you can subclass a class with static methods, and within the subclass, the 
> inherited methods can access other static attributes within the class, 
> without having to explicitly specify the class.

You can call a staticmethod of the parent from a staticmethod of the
children without naming the parent explicitely:

class B(object):
    f=staticmethod(lambda : 'I am B.f')

class C(B):
    def g():
        print C.__base__.f()

C.g() # => I am B.f

I was unable to do that with 'super', however. If somebody has a better
recipe I would be interested in knowing it.



More information about the Python-list mailing list