class Test:
def __init__(self):
self.number = 4000
self.msg = "Hiii"
def __getattr__(self, name):
if name=='message':
return self.msg
return AttributeError #<--------
d = Test()
print "-------d.message-------", d.message
print "-------d.number-------", d.number
print "-------d.msg-------", d.msg
OUTPUT
=========
-------d.message------- Hiii
-------d.number------- 4000
-------d.msg------- Hiii
More
More
No comments:
Post a Comment