[Python-ideas] setting function properties with a decorator syntax
Andrey Fedorov
anfedorov at gmail.com
Thu Mar 18 08:34:02 CET 2010
On Thu, Mar 18, 2010 at 2:49 AM, nbv4 <nbvfour at gmail.com> wrote:
> @printable=True
> def some_func(*args, **kwargs):
> return "sup"
>
> Any thoughts?
>
If you have that many properties, there's no need to extend the syntax, just
do something like:
def prop(**props):
def wee(f):
f.__dict__.update(props)
return f
return wee
@prop(printable=True, other_prop="yo!")
def some_func():
return "sup, %s" % some_func.other_prop
print some_func() # prints "sup, yo!"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100318/b99ffb24/attachment.html>
More information about the Python-ideas
mailing list