PDA

View Full Version : Python, method overriding and event handling



bigelectron
05-25-2011, 07:09 AM
Hey guys,

As you can probably tell from some of the stuff I've released, python isn't my main language. I have a question regarding scopes and overriding classes at runtime.

For example, lets say the eve target service. I override the OnTarget event with my OnTarget method(whatever.OnTarget = MethodType(what,ever,etc)). Now my question is when the OnTarget event fires and execution ends up on my OnTarget method, using "self" what is self in that context, is it still the targetSvc instance, is it an instance of the main thread, is it an instance of the event handler?

Let me know if that question makes any sense and if you know the answer thats even better!

asdfasdf100500
05-25-2011, 01:35 PM
i always thought "self" as c++'s/java's this. so my guess is self points to the instance of the class that contains your OnTarget override method

bigelectron
05-25-2011, 04:34 PM
i always thought "self" as c++'s/java's this. so my guess is self points to the instance of the class that contains your OnTarget override method

I thought so too but the behavior I'm seeing leads me to believe its a little different. For example say the method I have overriden OnTarget with is inside my FakeTarget class and lets say FakeTarget has a method called Paint() or something and inside my OnTarget method I do a call to self.Paint(). Then inside my script I have whatever = FakeTarget. whatever.OnTarget() that works. But when the OnTarget method gets called from the event handler it doesn't work.

I think the difference is that in c++/java self is an inherent member of the instance while in python its a parameter that is automatically passed when you do instance.Method, an its a parameter that points to instance. So when eve's eventhandler does service1.OnTarget, service1.OnTarget, etc, something other than my class is being called. Yet the behavior I'm seeing doesn't completely support this either so I'm not really sure whats going on.

If anyone else can shed some light on this that'd be awesome!

wibiti
05-25-2011, 06:35 PM
nevermind.