0

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 :)

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Gribouillis
0

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

Edited by qdiscoverer: n/a

0

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).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.