Instance variables vs. class variables in Python
- by deamon
I have Python classes, of which I need only one instance at runtime, so it would be sufficient to have the attributes only once per class and not per instance. If there would be more than one instance (what won't happen), all instance should have the same configuration. I wonder which of the following options would be better or more "idiomatic" Python.
Class variables:
MyController(Controller):
path = "something/"
childs = [AController, BController]
def action(request):
pass
Instance ariables:
MyController(Controller):
def __init__(self):
self.path = "something/"
self.childs = [AController, BController]
def action(self, request):
pass