I love the decorator in Python!!!
Thomas Rachel
nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Thu Dec 8 03:59:26 EST 2011
Am 08.12.2011 08:18 schrieb 88888 Dihedral:
> I use the @ decorator to behave exactly like a c macro that
> does have fewer side effects.
>
> I am wondering is there other interesting methods to do the
> jobs in Python?
In combination with a generator, you can do many funny things.
For example, you can build up a string:
def mkstring(f):
"""Turns a string generator into a string,
joining with ", ".
"""
return ", ".join(f())
def create_answer():
@mkstring
def people():
yield "Anna"
yield "John"
yield "Theo"
return "The following people were here: " + people
Many other things are thinkable...
Thomas
More information about the Python-list
mailing list