In normal python classes I can define class attributes like
class Example:
x = 3
def __init__(self):
pass
And if I then do Example.x
or Example().x
, I get 3
.
When I inherit pydantic's BaseModel
, I can't figure out how to define class attributes, because the usual way of defining them is overwritten by BaseModel.
For example:
class Example(BaseModel):
x = 3
print(Example.x)
--> type object 'Example' has no attribute 'x'
I want to be able to define class level attributes. What is the proper method/syntax for this?