How the event list be sent to EventManager?

S

steve

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'?
Anyhow the 'event' has not defined!
The 'event' dynamically get its own type through
isinstance(event,TickEvent):...?
 
F

Fredrik Lundh

steve said:
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>
 
S

steve

Can an argument to reference an object's attribute??

Fredrik said:
steve said:
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>
 
F

Fredrik Lundh

steve said:
Can an argument to reference an object's attribute??

sorry, cannot parse that sentence.

the arguments to a method are objects, and objects have attributes. why
do you find this surprising?

</F>
 
S

steve

Thank you,Fredrik,I see.

Fredrik said:
sorry, cannot parse that sentence.

the arguments to a method are objects, and objects have attributes. why
do you find this surprising?

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top