Well, it's classmethod/staticmethod in truth, @ is the decorator
operator:

def testdec(func):
    return {"funcobj": func}

class Abc(object):
    @testdec
    def method():
        pass

assert isinstance(Abc.method, dict)

Basically as you can see above, @X before a function definition takes
the function, applies X, and use the result instead.

Now, naive Python level implementations of classmethod and staticmethod
would be (untested, all typed in the mailer):

def classmethod(func):
    def wrapper(self, *args, **kw):
        return func(self.__class__, *args, **kw)
    return wrapper

def staticmethod(func):
    def wrapper(self, *args, **kw):
        return func(*args, **kw)
    return wrapper

Andreas

Am Freitag, den 21.03.2008, 20:08 -0700 schrieb maser:
> Hi
> 
> I couldn't find a good resource explaining what
> @classmethod and @staticmethod are in python and when,
> how these could be used.
> 
> If someone could explain what these are, or point me
> to resources that may help, it is appreciated.
> 
> Thanks
> iyer
> 
> 
>       
> ____________________________________________________________________________________
> Be a better friend, newshound, and 
> know-it-all with Yahoo! Mobile.  Try it now.  
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to