Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__init__() missing 1 required positional argument: 'quantity'

I am getting the error as shown in the question, and I can't figure out why. Even when trying other Stack Overflow methods of fixing this it doesn't work.

class Item(object):
    def __init__(self, name, style, quantity):
        self.name = name
        self.style = style
        self.quantity = quantity
    
class Weapon(Item):
    def __init__(self, name, style, quantity=1):
        Item.__init__(name, style, quantity,)

Bow = Weapon(name = "Bow", style = "WRanged", quantity = 1)

The lines affected with the error codes:

Traceback (most recent call last):
  File "C:\Stuff\SG\Work\Inventory.py", line 33, in <module>
    Bow = Weapon(name = "Bow", style = "WRanged", quantity = 1)
  File "C:\Stuff\SG\Work\Inventory.py", line 12, in __init__
    Item.__init__(name, style, quantity,)
TypeError: __init__() missing 1 required positional argument: 'quantity'
like image 437
aimcreeper Avatar asked Nov 29 '25 03:11

aimcreeper


1 Answers

Change

Item.__init__(name, style, quantity,)

for

super().__init__(name, style, quantity)
like image 144
rafaelc Avatar answered Dec 01 '25 18:12

rafaelc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!