hmm, lets call it: generic __init__ problem ['LBBW': checked]

Holger Joukl Holger.Joukl at LBBW.de
Thu Feb 19 11:00:17 EST 2004


I just started out with python 2.3, so I might be totally wrong,
but does this work?

>>> class one(object):
...     def __init__(self, *args, **kwargs):
...             super(self.__class__, self).__init__()
...
>>> one()
<__main__.one object at 0x1dd190>
_________________________________

Holger Joukl
Landesbank Baden-Württemberg
1651 Financial Markets Technologies
fon +49 (711) 124 - 7078
fax +49 (711) 124 - 3759
_________________________________

__________________


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
--
 http://mail.python.org/mailman/listinfo/python-list

Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene
Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde,
verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail
sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht
gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht
garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte
den Inhalt der E-Mail als Hardcopy an.

The contents of this  e-mail are confidential. If you are not the named
addressee or if this transmission has been addressed to you in error,
please notify the sender immediately and then delete this e-mail.  Any
unauthorized copying and transmission is forbidden. E-Mail transmission
cannot be guaranteed to be secure. If verification is required, please
request a hard copy version.







More information about the Python-list mailing list