[Tutor] Multiple inheritance

Phil phillor9 at gmail.com
Fri May 14 05:27:09 EDT 2021


On 14/5/21 5:04 pm, Cameron Simpson wrote:

Thank you Cameron,
> This seems to have a bunch of "blank" characters which are not Python
> indentation characters (space, TAB). Like, 0xa0 and embedded DEL
> characters. Is this cut/paste from your actual code?
The code was copied from IDLE and pasted directly into Thunderbird. If 
need be, I'll copy and past from Visual Studio Code.
>
> But it does! Try printing MyForm.__mro__ to see the method resolution
> order.
I will.
>
>> import wx
>> import math
>>
>> class Meter():
> You don't need the () in Python 3.

I had tried without the braces.


>>      def __init__(self):
>>          wx.Frame.__init__(self, None, wx.ID_ANY, "Meter Test", size=(300, 300))
>>          # This results in a syntax error
>>          Meter.^?^?^?^?__init__(self, start_x)
> Well, yeah! There are literal DEL characters in there!
>
> If you clean that up, or just retype it, it should work.
Those characters aren't in the original file and Meter.__init__(self, 
start_x) results in a syntax error.
>
> But... Where does start_x come from? I don't see it in the arguments to
> MyForm.__init__.

start_x is a variable in the Meter class. Maybe what I'm trying to 
achieve is the problem? What I'd like to do is create a Meter class so 
that I can import it into some other programme.


> super().method is good to finding method in a superclass. Here you need
> to call each superclass __init__ separately with distinct arguments.

Super, from what I've read, is not really necessary. It sounds like a 
complication that I can do without, at least for now.


>
>>          self.InitUI()
>>
>>      def InitUI(self):
>>
>>          self.Bind(wx.EVT_PAINT, self.OnPaint)
>>
>>          panel = wx.Panel(self, wx.ID_ANY)
>>
>>          self.timer = wx.Timer(self)
>>          self.Bind(wx.EVT_TIMER, self.update, self.timer)
>>          self.timer.Start(100)
>>
>>      def update(self, event):
>>          m = Meter(200) # m.self.angle etc is not correct here.
>> Shouldn't the Meter class variables
>>                                      #  be inherited and be useable with
>> the need for m.self?
> Yes. Once you fix your Meter.__init__(self,...) above it should be fine.

I retyped that line in Visual Studio (Pylance), just in case, and the 
error is "invalid character in identifier". However, selecting __init__ 
from the suggestion list solved that problem. Start_x generates a "not 
defined error". As above, start_x is a Meter class variable. How do I 
get around that problem?

-- 

Regards,
Phil



More information about the Tutor mailing list