Mar-14-2018, 10:24 AM
print("__main__.py") def Tracer(aClass): class Wrapper: def __init__(self, *args, **kargs): self.fetcges=0 self.wrapped=aClass(*args, **kargs) def __getattr__(self, attrname): print('Trace: '+ attrname) self.fetches +- 1 return getattr(self.wrapped, attrname) return wrapper if __name__=='__main__': @Tracer class Spam: def display(self): print('Spam!' * 8) @Tracer class person: def __init__(self, name, hours, rate): self.name=name self.hours=hours self.rate=rate def pay(self): return self.hours * self.rate food=Spam() food.display() print([food.fetches]) bob=Person('Bob', 40, 50) print(bob.name) print(bob.pay()) print('') sue=Person('Sue', rate=100, hours=60) print(sue.name) print(sue.pay()) print(bob.name) print(bob(pay()) #print([bob.fetches], [sue.fetches]) #print([bob.fetches, sue.fetches]) print('end of file!') print('end!!!!')
Error:C:\Users\Sylvain\fs>python __main__.py
File "__main__.py", line 51
print('end of file!')
^
SyntaxError: invalid syntax