File: class/Workbook/Examples/Lecture12/person2.py
# a person object: fields + behavior # change: the tax method is now a virtual member class Person: def __init__(self, name = '', job = '', pay = 0): self.name = name self.job = job self.pay = pay # real instance data def __getattr__(self, attr): # on person.attr if attr == 'tax': return self.pay * 0.30 # computed on access else: raise AttributeError # other unknown names def info(self): return self.name, self.job, self.pay, self.tax bob = Person('Bob', 'dev', 50000) print bob.tax raw_input()