26 lines
385 B
Python
26 lines
385 B
Python
# 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}')
|
|
|
|
|