#1.“_getattribute_”只适用于所有的“.”运算符;
#2.“_getitem_”只适用于所有的“[]”运算符;
class Squanchi(object):
def __init__(self,username,age):
self.username=username
self.age=age
def __getattribute__(self,attr):
returnsuper(Squanchi,self).
__getattribute__(attr)
def __getitem__(self,attr):
returnsuper(Squanchi,self).
__getattribute__(attr)
sq=Squanchi('squanchi',32)
print(sq.username)
print("现在支持“[]”运算符,format(sq['username']的值是{},""sq['ag']的值是{}".format(sq['username'],sq['age']))