9 ms·
For me the point is that __init__ is special - it's the language's the way to construct an object. If we want to side-effecting code we can with a non-special s
by duncanfwalker 1y ago
For me the point is that __init__ is special - it's the language's the way to construct an object. If we want to side-effecting code we can with a non-special static constructor like
class Foo
@classmethod
def connect():
return Foo()._connect()
The benefit is that we can choose when we're doing 1) object construction, 2) side-effecting 3) both. The downside is client might try use the __init__() so object creation might need to be documented more than it would otherwise
- rcxdude 1y agoInit isn't really special (especially compared to e.g. __new__). It has no special privileges, it's just a method that is called when you construct an instance of the class.