Liu Zuo Lin
Sep 23, 2022

--

I use dataclasses when I want to quickly write a class without having to write an __init__ function. As for using type() to create a class, I don't usually use it (there's not a lot of need to!)

Theoretically, we can use type() to dynamically create classes (check out Python metaclasses) but we very seldom need it in a real world context (at least in my experience)

--

--

Liu Zuo Lin
Liu Zuo Lin

Written by Liu Zuo Lin

SWE @ Meta | [Ebook] 101 Things I Never Knew About Python: https://payhip.com/b/vywcf

Responses (1)