Verzeichnis für teil28
This commit is contained in:
25
teil28/classdecor.py
Normal file
25
teil28/classdecor.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Datei: classdecor.py
|
||||
|
||||
|
||||
def addrepr(cls):
|
||||
# Universelle __repr__ Methode
|
||||
def __repr__(self):
|
||||
return f"{cls.__name__}({self.__dict__})"
|
||||
cls.__repr__ = __repr__
|
||||
|
||||
return cls
|
||||
|
||||
@addrepr
|
||||
class Fahrzeug():
|
||||
def __init__(self,farbe,typ):
|
||||
self.typ = typ
|
||||
self.farbe = farbe
|
||||
|
||||
|
||||
f1 = Fahrzeug('grau','VW')
|
||||
f2 = Fahrzeug('rot','Ferrari')
|
||||
|
||||
print(f'{f1}')
|
||||
print(f'{f2}')
|
||||
|
||||
|
Reference in New Issue
Block a user