Antwort: Play with classes ['LBBW': checked]
Holger Joukl
Holger.Joukl at LBBW.de
Thu Feb 26 07:05:54 EST 2004
I have the following classes defined
ModeA, ModeB, TypeA, TypeB, TypeC, SubtypeA, SubtypeB.
Supose the user whant to combine ModeA with TypeB and SubtypeB, so I need
something like
class UserClass(ModeA, TypeB, SubtypeB):
pass
_________________________________
You might do
>>> class A:
... a=1
...
>>> class B:
... b=2
...
>>> exec("class UserClass(A, B): pass")
>>> u = UserClass()
>>> u
<__main__.UserClass instance at c7930>
or even with methods, but you need correct indentation:
>>> exec("""
... class UserClass(A, B):
... def __init__(self):
... print "UserClass.__init__"
... """)
>>> UserClass
<class __main__.UserClass at b7880>
>>> u=UserClass()
UserClass.__init__
Greetings
Holger
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