Em 2008/12/11, às 00:33, Artie Ziff escreveu:
Looking at the examples on the "IronPython & Windows Forms" page, I
see
a code that I am not familiar. In the 2nd example on this page,
<http://www.voidspace.org.uk/ironpython/winforms/part5.shtml>, I am
unfamiliar with placing a method (in this case "update") inside a
constructor.
I see that the method "update" is being added to the button's event
handler in the constructor, __init__. Why must this method be defined
inside the constructor? Is there a name for this? Is this an example
of
a PEP 309, Partial Function Application?
Actually, it's not a method. Methods take self as the first argument.
that update is just a function that takes two parameters and prints
some value. It's the callback of that event.
After you call
self.button1.Click += update
Everytime button1 is clicked, it is going to call the function update.
You can define functions anywhere in your code, inside classes, inside
other functions, at the module level, etc... Methods are the ones that
are restricted to be inside the class and taking self as the first
parameter*
Alcides
* Actually you can monkey patch, but that's an advanced feature.
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com