Here's what I made to test how python works....
test.py:

class ECollector:
    #error msg collector
    #this class should be used as 'global'
    msgs = []
    def addmsg(self,msg):
        self.msgs.append(msg)
    def clear(self):
        self.msgs = []
class test(ECollector):
    dcodes = []
    ECollector
    def new(self):
        ECollector.addmsg("test!")

And I typed the following on the Python console
(I'm working on Python 3.12 with Pyscripter 2.3)
>>>a = test()
>>>a.new()

and the following is what I got:

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\...\test.py", line 14, in new
    ECollector.addmsg("test!")
TypeError: addmsg() takes exactly 2 positional arguments (1 given)

What I don't get is this: why is Python requiring 2 arguments?
I thought this 'self' argument was 'automatically-filled' kind of argument...
(in other words, I thought it's unnecessary to fill the 'self' argument...)

Also, I tried to fill in the self argument like this:

class test(ECollector):
    dcodes = []
    ECollector
    def new(self):
        ECollector.addmsg(ECollector"test!")

This doesn't work either :(


I'm confused about this 'phenomenon' T.T

Anyway, please 'redeem' this bewildered newbie giving him some answers :)

Sorry. I thought I was wrong about the code...please delete this reply post.

Here is how you should write this

class ECollector:
    #error msg collector
    #this class should be used as 'global'
    def __init__(self):
        self.msgs = []
    def addmsg(self,msg):
        self.msgs.append(msg)
    def clear(self):
        self.msgs = []
class test(ECollector):
    def __init__(self):
        ECollector.__init__(self)
        self.dcodes = []
    def new(self):
        self.addmsg("test!")

You are mistaking classes for class instances (it's like mistaking the dog species for your favorite pet).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.