Should all member variables be initialized in __init__

In object-oriented programming it’s up to the developer to ensure an object is always in a consistent state after instantiation and after a method finishes. Other than that you’re free to develop the class as you wish (keeping in mind certain principles with subclassing / overriding and so on).

A tool such as Pylint will warn when you’re setting instance variables outside __init__. It can be argued that setting all instance variables in the __init__ is cleaner but it’s not a rule that must be abided by at all times.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)