.__ new __ () object does not accept parameters

So, I made a custom class:

class Drinker: def __init__(self, name, age): self.name = name self.age = age def canYouDrink(self): if self.age > 20: print('yes') else: print('no') 

In a command prompt window, I did:

 from drinker import Drinker dan = Drinker("Dan", 21) 

Then he gave me this error message object.__new__() takes no parameters . Am I defining my constructor incorrectly?

+4
source share
1 answer

There is nothing wrong with the code. Try closing and reopening the interactive session to make sure that the module is really rebooting. Otherwise, make sure the module loads from the right place (if you have more than one copy of drinker.py ).

+2
source

All Articles