staticmethod() problems

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


Aum <spam-me at no-thanks.com> wrote in message news:<YMRX9.43233$F63.924790 at news.xtra.co.nz>...
> 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()
    g=staticmethod(g)

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.

Cheers,

                                                         Michele




More information about the Python-list mailing list