Re: decorators ?
From: Josiah Carlson (jcarlson_at_uci.edu)
Date: 11/30/04
- Next message: Peter Hansen: "Re: date diff calc"
- Previous message: Skip Montanaro: "Re: comment out more than 1 line at once?"
- Next in thread: Paul McGuire: "Re: decorators ?"
- Maybe reply: Paul McGuire: "Re: decorators ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 30 Nov 2004 10:46:25 -0800 To: km <km@mrna.tn.nic.in>, python-list@python.org
km <km@mrna.tn.nic.in> wrote:
>
> Hi all,
> was going thru the new features introduced into python2.4 version.
> i was stuck with 'decorators' - can someone explain me the need of such a thing called decorators ?
Decorators are not 'needed'. They are a convenience.
Among the things that they are meant to make more convenient are the
following...
class foo:
@staticmethod
def goo(arg, ...):
pass
rather than...
class foo:
def goo(arg, ...):
pass
goo = staticmethod(goo)
And other things of its ilk. Where they will be used the most right off
is in function signatures for PyObjC bindings in (I believe) OSX by Bob
Ippolito. Using his example:
class FooClass(NSObject):
def returnsAnInteger(self):
return 1
returnsAnInteger = objc.selector(returnsAnInteger, signature='i@:')
def returnsVoidTakesAnInteger_(self, anInteger):
pass
returnsVoidTakesAnInteger_ = \
objc.selector(returnsVoidTakesAnInteger_, signature='v@:i')
...becomes...
def signature(sig):
def _signature(fn):
return objc.selector(fn, signature=sig)
return _signature
class FooClass(NSObject):
@signature('i@:')
def returnsAnInteger(self):
return 1
@signature('v@:i')
def returnsVoidTakesAnInteger_(self, anInteger):
pass
- Josiah
- Next message: Peter Hansen: "Re: date diff calc"
- Previous message: Skip Montanaro: "Re: comment out more than 1 line at once?"
- Next in thread: Paul McGuire: "Re: decorators ?"
- Maybe reply: Paul McGuire: "Re: decorators ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|