
cu
ertlpott
Code: Alles auswählen
>>> class Test:
... def __init__(self, wert="Hallo Welt"):
... self.text = wert
...
>>> objekt = Test()
>>> print objekt.text
Hallo Welt
>>> objekt = Test("Ein anderer Text")
>>> print objekt.text
Ein anderer Text
Code: Alles auswählen
class meta:
def __init__(self,objekt):
self.data = objekt
def __getattr__(self,other):
print "Trace", other
return getattr(self.data)
def __setattr__(self,other,wert):
print "Trace", other,"=",wert
self.other=wert
Code: Alles auswählen
>>> import sys
>>> sys.path.append("h:\\programme\\klassen")
>>> import meta
>>> x = meta.meta("sabel")
Trace data = sabel
Trace other = sabel
Trace other = sabel
Trace other = sabel
Trace other = sabel
Trace other = sabel
Trace other = sabel
Trace other = sabel
Trace other = sabel
Trace other = sabel
Trace other = sabel
Trace other = sabel
Trace other = sabel
Code: Alles auswählen
class meta:
def __init__(self,objekt):
self.data = objekt
def __getattr__(self,other):
print "Trace", other
return self.__dict__[other]
def __setattr__(self,other,wert):
print "Trace", other,"=",wert
self.__dict__[other] =wert