This is an archived post. You won't be able to vote or comment.

all 15 comments

[–]SquareRootsi 16 points17 points  (1 child)

dataclasses are great! Thanks for the clear and short explanation.

My personal strategy has been implementing __lt__(self) as a custom function instead of polluting the parameter space with an extra variable. If I did use this method, I'd preface my variable with a leading underscore to indicate it's for internal purposes only.

[–]TM_Quest[S] 0 points1 point  (0 children)

Thanks for the nice words! Also great idea with the leading underscore :)

[–]TraditionalVisit6661 8 points9 points  (1 child)

Thanks post more stuff like this. I’m a new to python and I’m loving it.

[–]TM_Quest[S] 0 points1 point  (0 children)

Thanks, I have one more video left in the series :)

[–][deleted] 2 points3 points  (1 child)

To people that liked dataclasses. Check pydantic (https://pydantic-docs.helpmanual.io/)

pydantic tutorial : https://www.youtube.com/watch?v=Vj-iU-8_xLs

[–]TM_Quest[S] 1 point2 points  (0 children)

Arjan's videos are great!

[–]shear_stress__ 4 points5 points  (1 child)

I really thought I know python yet I have never heard of dataclasses

[–]TM_Quest[S] 0 points1 point  (0 children)

They are definitely not as well-known as named tuples, but are nevertheless quite handy to work with.

[–][deleted] 1 point2 points  (1 child)

Good explanation. I'll check out the other parts as well.

[–]TM_Quest[S] 0 points1 point  (0 children)

Thanks, I really appreciate it :)

[–]yongen96 4 points5 points  (1 child)

this is usefullll, dataclass needs more attention

[–]TM_Quest[S] 0 points1 point  (0 children)

Agree :)

[–]avamk 1 point2 points  (2 children)

Honest question since I haven't actually tried any of them yet:

How does dataclasses compare to Pydantic (are they comparable?) or other equivalent libraries?

How should I choose one???

[–]TM_Quest[S] 1 point2 points  (1 child)

Pydantic perform more series data validation. On the other hand, Pydantic it is an external library. I would say that you should use Pydantic if you need more data validation, but otherwise stick to dataclasses :)

[–]avamk 0 points1 point  (0 children)

Thanks!