Call for signatories for J2
Michael Sparks
michaels at rd.bbc.co.uk
Thu Aug 26 09:44:27 EDT 2004
Pierre-Frédéric Caillaud wrote:
> Can we insert conditional expressions in the decorator list ?
Not directly, but yes. Both J2 and A1 are "limited" to putting just
values that resolve to a function in the decorator list. In practice
this means that if you REALLY want to do things like conditional
expressions you can:
Given:
x=1
def memoise(f):
print "memoise"
return f
def esiomem(f):
print "esiomem"
return f
Using current syntax: (untested)
class Foo:
@staticmethod
@eval("(memoise,esiomem)[x==0]")
def Hoo(Who, *args):
print "Yoo", Who
Using proposed J2: (tested)
class Foo:
using:
staticmethod
eval("(memoise,esiomem)[x==0]")
def Hoo(Who, *args):
print "Yoo", Who
Personally that strikes me as relatively evil, but it works.
Regards,
Michael.
--
Michael.Sparks at rd.bbc.co.uk
British Broadcasting Corporation, Research and Development
Kingswood Warren, Surrey KT20 6NP
This message (and any attachments) may contain personal views
which are not the views of the BBC unless specifically stated.
More information about the Python-list
mailing list