IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Python question: Events
So, I'm trying to grok Python, and I'm doing a fairly good job at it, but I just want to make sure I'm not missing something.

In VB/C#/Java, there is the concept of the "Raised Event" - an event within an object that triggers an external function, without ending the object itself as a raised exception would. You can simulate something like this by the external creator assigning a function to a property in the object, and perhaps this is the way it is intended to be done in Python.

Am I correct, or has my rapid pace through the tutorials I have read made me miss something? Is there a reason that the "Raised Event" model of programming in Java/C#/VB inherently Evil (other than the fact that 2 of the 3 are M$ languages, and the third is Java) or is this just something that the Python Powers That Be decided not to implement?

Hope that made sense...
I have a red sign on my door. It says "If this sign is blue, you're going too fast."
New Look at the threading module in the library
...which has garden-variety thread support (semaphores, queues, events, rlocks, etc.). You should be able to find something for your needs. I haven't used 'raise event'--is that just a glorified callback?
I was one of the original authors of VB, and *I* wouldn't use VB for a text
processing program. :-)
Michael Geary, on comp.lang.python
New Re: Look at the threading module in the library
I haven't used 'raise event'--is that just a glorified callback?


Something like that. Quoting from the C# language specification, 1.7.5 Events:

An event is a member that enables an object or class to provide notifications. A class defines an event by providing an event declaration, which resembles a field declaration, though with an added event keyword, and an optional set of event accessors. The type of this declaration must be a delegate type.

An instance of a delegate type encapsulates one or more callable entities. For instance methods, a callable entity consists of an instance and a method on that instance. For static methods, a callable entity consists of just a method. Given a delegate instance and an appropriate set of arguments, one can invoke all of that delegate instance\ufffds methods with that set of arguments.


Just was wondering if I saw the way it's supposed to be done, or if I was missing it. In Python, it looks like you add a function to the list of functions for that event. When the "event" triggers, you walk through the list of functions, and call them.
I have a red sign on my door. It says "If this sign is blue, you're going too fast."
New Python idiom
Given that functions are objects in Python, you can "register" both the instance and its method in one operation:

>>> class Thing(object):
... \tdef aMethod(self, aParam):
... \t\tself.Value = aParam * 3
... \t\t
>>> some = Thing()
>>> some.aMethod
<bound method Thing.aMethod of <__main__.Thing object at 0x0128CE90>>
>>> f = some.aMethod
>>> f(4)
>>> print some.Value
12

In this example, f gets bound to the method for the "some" instance.
I was one of the original authors of VB, and *I* wouldn't use VB for a text
processing program. :-)
Michael Geary, on comp.lang.python
     Python question: Events - (inthane-chan) - (3)
         Look at the threading module in the library - (FuManChu) - (2)
             Re: Look at the threading module in the library - (inthane-chan) - (1)
                 Python idiom - (FuManChu)

Those chicken wings are really spicy! Don't eat those!
34 ms