How the event list be sent to EventManager?

Fredrik Lundh fredrik at pythonware.com
Thu Oct 26 02:44:08 EDT 2006


steve wrote:

> The example code from: http://sjbrown.ezide.com/games/example1.py.html
> ...
> def Notify( self, event ):
>                 if not isinstance(event, TickEvent): Debug( "
> Message: " + event.name )
>                 for listener in self.listeners.keys():
>                         #If the weakref has died, remove it and
> continue
>                         #through the list
>                         if listener is None:
>                                 del self.listeners[ listener ]
>                                 continue
>                         listener.Notify( event )
> 
> I can not figure out how 'event' can has reference to 'event.name'?

because the developer expects you to pass in an object that has a name 
attribute ?  (one of the Event types defined at the top of that module,
most likely).

> Anyhow the 'event' has not defined!

it's an argument to the method.

> The 'event' dynamically get its own type through
> isinstance(event,TickEvent):...?

no, that line simply checks if it's a specific Event type, and enables 
debug logging for all other event types.

</F>




More information about the Python-list mailing list