hmm, lets call it: generic __init__ problem

paul kölle koelle1 at uni-weimar.de
Thu Feb 19 16:34:52 CET 2004


Michele Simionato wrote:
> This is probably not what you want:
It's not about importing attributes rather than having only one 
definition of __init__ in one "metaclass" wich should behave differently 
  dependent on the name of the subclass (see my answer to Peter). I 
found out I have to read lots of stuff to catch up with concepts of 
new-style classes and metaclass design.

  The solution using super() like Peter suggested is almost perfect 
except the name of the class is still hardcoded inside of __init__.

one(object):
   def __init__(self, *args, **kwargs):
     super(one, self).__init__()
           ^^^^
     r = self.s.get_obj(ldap.schema.ObjectClass, self.__class__.__name__)
     ...process r...

implies to write another __init__ for every subclass, since "one" wouldn 
't match the subclass's name right? Instead of "one" I'd like to have 
something that get's the current class at instantiation time. Is that 
possible ?

thanks a lot for all your time and help.
  Paul



More information about the Python-list mailing list