__init__() takes from 1 to 3 positional arguments but 4 were given

Hugh Craig
class GeometricObject:
    def __init__(self,color = 'green',filled='true'):
        self.__color=color
        self.__filled=filled
    def getColor(self):
        return self.__color
    def setColor(self,color):
        self.__color=color
    def isFilled(self):
        return self.__filled
    def setFilled(self,filled):
        self.__filled=filled
    def __str__(self):
        return "Color: " + self.__color + " Filled: " + str(self.__filled)

And this is the Triangle class:

   from GeometricObject import GeometricObject

   class Triangle(GeometricObject):
       def __int__(self,side1=1.0,side2=1.0,side3=1.0):
           super().__init__()
           self.__side1=side1
           self.__side2=side2
           self.__side3=side3

       def getPerimeter(self):
           return self.__side1 + self.__side2 + self.__side3

       def __str__(self):
           return super().__str__()+" side 1: "+str(self.__side1)+" side 2: "+str(self.__side2)+" side 3: "+str(self.__side3) 

       from triangle import Triangle
       from GeometricObject import GeometricObject

       def main():
           side1=int(input("Enter first side: "))
           side2=int(input("Enter second side: "))
           side3=int(input("Enter third side: "))
           t1=Triangle(side1,side2,side3)
           print(t1.getColor())
           print(t1.getPerimeter())
           print(t1.__str__())
       main()

The error is occuring when I create the triangle object t1 in the main function: init() takes from 1 to 3 positional arguments but 4 were given...

I know there is other posts on similar errors like this but a lot of them were if you provided not enough arguments and the one's that did provide too many arguments did not answer my question.

Steve P.

You need to change __int__ to __init__, and only pass super() self.

class Triangle(GeometricObject):
       def __init__(self,side1=1.0,side2=1.0,side3=1.0):
           #The correct alternative to below is: 
           #super(GeometricObject, self).__init__()

           GeometricObject.__init__(self) 
           self.__side1=side1
           self.__side2=side2
           self.__side3=side3

To answer your second question, here's an example:

class A(object):
    def __init__(self, color = 'blue'):
        self.color = color

    def __str__(self):
        return str(self.color)

class B(A):
    def __init__(self, name = 'steve'):
        A.__init__(self)    
        self.name = name

    def __str__(self):
        #alternatively: return super(B, self).__str__() + " " + str(self.name) 
        return A.__str__(self) + " " + str(self.name)

prints "blue steve"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

TypeError: __init__() takes from 1 to 3 positional arguments but 4 were given

From Dev

Money and TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

From Dev

Money and TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

From Dev

TypeError: __init__() takes 4 positional arguments but 7 were given

From Dev

Python: __init__() takes 2 positional arguments but 3 were given

From Dev

__init__() takes 3 positional arguments but 4 were given when run

From Dev

TypeError: __init__() takes 1 positional argument but 3 were given

From Dev

Odoo takes from 1 to 2 positional arguments but 3 were given

From Dev

python super :TypeError: __init__() takes 2 positional arguments but 3 were given

From Dev

TypeError: randint() takes 3 positional arguments but 4 were given

From Dev

TypeError: predict() takes from 1 to 2 positional arguments but 4 were given, google cloud shell

From Dev

TypeError: init_animals() takes 1 positional arguments but 2 were given

From Dev

TypeError: init_animals() takes 1 positional arguments but 2 were given

From Dev

TypeError: _transform() takes 2 positional arguments but 3 were given

From Dev

Unexpected error: replace() takes 2 positional arguments but 3 were given

From Dev

TypeError: forward() takes 2 positional arguments but 3 were given

From Dev

TypeError: chunkIt() takes 2 positional arguments but 3 were given

From Dev

How to resolve error "object_permission() takes 3 positional arguments but 4 were given"?

From Dev

Python/MySQL TypeError: execute() takes from 2 to 4 positional arguments but 5 were given

From Java

Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given

From Dev

Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given

From Dev

Django client get: TypeError: __init__() takes 1 positional argument but 2 were given

From Dev

Caught up in a Type Error: __init__() takes 1 positional argument but 2 were given

From Dev

Pygame TypeError: __init__ takes exactly 4 arguments (1 given)

From Dev

TypeError: __init__() takes at least 3 arguments (1 given)

From Dev

TypeError : takes 0 positional arguments but 3 were given. Can't figure out what arguments

From Java

Using a LabelEncoder in sklearn's Pipeline gives: fit_transform takes 2 positional arguments but 3 were given

From Dev

sklearn.compose.ColumnTransformer: fit_transform() takes 2 positional arguments but 3 were given

From Dev

TypeError: open() takes 0 positional arguments but 2 were given

Related Related

  1. 1

    TypeError: __init__() takes from 1 to 3 positional arguments but 4 were given

  2. 2

    Money and TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

  3. 3

    Money and TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

  4. 4

    TypeError: __init__() takes 4 positional arguments but 7 were given

  5. 5

    Python: __init__() takes 2 positional arguments but 3 were given

  6. 6

    __init__() takes 3 positional arguments but 4 were given when run

  7. 7

    TypeError: __init__() takes 1 positional argument but 3 were given

  8. 8

    Odoo takes from 1 to 2 positional arguments but 3 were given

  9. 9

    python super :TypeError: __init__() takes 2 positional arguments but 3 were given

  10. 10

    TypeError: randint() takes 3 positional arguments but 4 were given

  11. 11

    TypeError: predict() takes from 1 to 2 positional arguments but 4 were given, google cloud shell

  12. 12

    TypeError: init_animals() takes 1 positional arguments but 2 were given

  13. 13

    TypeError: init_animals() takes 1 positional arguments but 2 were given

  14. 14

    TypeError: _transform() takes 2 positional arguments but 3 were given

  15. 15

    Unexpected error: replace() takes 2 positional arguments but 3 were given

  16. 16

    TypeError: forward() takes 2 positional arguments but 3 were given

  17. 17

    TypeError: chunkIt() takes 2 positional arguments but 3 were given

  18. 18

    How to resolve error "object_permission() takes 3 positional arguments but 4 were given"?

  19. 19

    Python/MySQL TypeError: execute() takes from 2 to 4 positional arguments but 5 were given

  20. 20

    Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given

  21. 21

    Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given

  22. 22

    Django client get: TypeError: __init__() takes 1 positional argument but 2 were given

  23. 23

    Caught up in a Type Error: __init__() takes 1 positional argument but 2 were given

  24. 24

    Pygame TypeError: __init__ takes exactly 4 arguments (1 given)

  25. 25

    TypeError: __init__() takes at least 3 arguments (1 given)

  26. 26

    TypeError : takes 0 positional arguments but 3 were given. Can't figure out what arguments

  27. 27

    Using a LabelEncoder in sklearn's Pipeline gives: fit_transform takes 2 positional arguments but 3 were given

  28. 28

    sklearn.compose.ColumnTransformer: fit_transform() takes 2 positional arguments but 3 were given

  29. 29

    TypeError: open() takes 0 positional arguments but 2 were given

HotTag

Archive