I'm learning classes in python. Also trying to learn dataclasses.
from dataclasses import dataclass
class Person():
name: str
age: int
height: float
email: str
person = Person('Joe', 25, 1.85, '[email protected]')
print(person.name)
Error:
TypeError: Person() takes no arguments
Unsure why.
You didn't decorate your class with the
@dataclassdecorator you've imported, so it's just a plain old class that has a bunch of annotations but no specific__init__, so it inheritsobject's__init__, which takes no arguments.would have
dataclassdo its magic to read those annotations and add the constructor and everything else dataclasses do.