Hey, I have been using the Pymt library and they have this convention to referring their widgets:
from pymt import *
# create a slider from 0.-1.
sl = MTXYSlider()
@sl.event
def on_value_change(x, y):
print 'Slider value change', x, y
runTouchApp(sl)
what's with the "@"? What does it signify in Python?Thanks.
asked Oct 27, 2010 at 8:37
Gooner
1,3962 gold badges15 silver badges25 bronze badges
-
How sad that the Python tutorials weren't working. Which tutorial have you been using? How long has it been down?S.Lott– S.Lott2010年10月27日 10:23:25 +00:00Commented Oct 27, 2010 at 10:23
2 Answers 2
It signifies a decorator
answered Oct 27, 2010 at 8:40
John La Rooy
306k54 gold badges378 silver badges514 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
basically it is a function that takes another function as an argument . if is a way python implements a Decorator Pattern.
the equivalent code would be
sl.event(on_value_change(x, y))
answered Oct 27, 2010 at 8:46
mossplix
3,8753 gold badges29 silver badges33 bronze badges
Comments
lang-py