0

This is the strangest thing. My python has just stopped handling classes with multiple parameters in their ctors? Running python 3.8.10 getting error TypeError: Person() takes 1 positional argument but 2 were given

def Person(object):
    def __init__(self, a, b):
        self.aa = a
        self.bb = b

pp = Person(20, 40)

If I bring the Person __init__ down to one parameter, then it works. If I raise it to 3, then I get the same takes 1 but 3 were given error. I'm totally stumped?

wjandrea
  • 28,235
  • 9
  • 60
  • 81
user2183336
  • 706
  • 8
  • 19

1 Answers1

4

You've declared your Person class wrong. You used def instead of class, meaning that you actually have a function called Person with a local function called __init__.

Try this:

class Person(object):
    def __init__(self, a, b):
        self.aa = a
        self.bb = b
Rafael de Bem
  • 641
  • 7
  • 15
  • Yes! The first time I've ever done this one... Found it here as you posted: https://stackoverflow.com/a/66549060/2183336 – user2183336 Aug 12 '22 at 01:10
  • 1
    Have you not been sleeping very well perhaps? Lol. This happens to all of us at least once, or at least once a day in my case. – Rafael de Bem Aug 12 '22 at 01:11