TypeError: method takes 0 positional arguments but 1 was given in Python
I just recently started coding at my school and am learning to use Python. And I created an object class
CustomerInfo as below:
class CustomerInfo: def __init__ (): self.name = name self.order = order self.quantity = quantity self.address = address def setName( self, newName ): self.Name = newName def setOrder ( self, newModel ): self.model = newModel def setQuantity ( self, newQuantity ): self.quantity = newQuantity def setAddress (self, newAddress ): self.address = newAddress def getName ( self ): return self.name def getOrder ( self ): return self.order def getQuantity ( self ): return self.quantity def getAddress ( self ): return self.address name = input("Enter your name: ") order = input("Enter your order: ") quantity = int(input("Enter your quantity: ")) address = input("Enter your address: ") customerObj = CustomerInfo() print ( "Name: ", customerObj.name) print ( "Order: ", customerObj.order) print ( "Quanity: ", customerObj.quantity) print ( "Address: ", customerObj.address)
I want to take input some information of customers like name, order, quantity and address but I get an exception TypeError: __init__() takes 0 positional arguments but 1 was given.
Enter your name: Python Enter your order: 23 Enter your quantity: 21 Enter your address: 333 West USA Traceback (most recent call last): File "main.py", line 32, in <module> customerObj = CustomerInfo() TypeError: __init__() takes 0 positional arguments but 1 was given
How can I fix it? Anyone can explain to me.
Thanks for any suggestions.
Leonardo Urbano Sep 05 2021
__init__ ()should be accepted
selfin Python because, well, it's a method.
def __init__ ():
def __init__ (self):
And it solved the issue for you.
Watcharapong Jakkawannorasing Sep 05 2021
Hey, I think this is the message throw when you forget
__init__()or any other method.
selfparam and it is solved for you.