I want to allow anyone that has never coded to make classes depending on my template with little to no knowledge of Python.
These classes need to do 2 things:
- Inherit from other classes similar to them.
- Contain variables, updating values if they have been changed or keeping them if not.
For the sake of simplicity I don't want to have
super() on these new classes, as I'm trying to not frighten newcomers with things they can't understand yet. Here's how I did it:
class Template(object): def __init__(self): self.value = "hello" self.other_value = "bonjour" self.constant_value = 42 current_class = self.__class__ inits =  while (current_class.__name__ != "Template"): inits.append(current_class.init) current_class = current_class.__bases__ for i in reversed(inits): i(self) def init(self): pass def info(self): print self.value print self.other_value print self.constant_value print "" class Deep(Template): def init(self): self.value = "howdy" self.other_value = "salut" class Deeep(Deep): def init(self): self.value = "hi" class Deeeep(Deeep): def init(self): self.value = "'sup" very_deep = Deeeep() not_so_deep = Deep() very_deep.info() not_so_deep.info()
This outputs :
sup salut 42 howdy salut 42
Which is exactly what I want, but it looks really weird, obfuscated and non-Pythonic. Any ideas for improvements?