在Python当我致电hasattr上@property装饰的hasattr功能,实际运行的@property代码块.
例如一堂课:
class GooglePlusUser(object):
def __init__(self, master):
self.master = master
def get_user_id(self):
return self.master.google_plus_service.people().get(userId='me').execute()['id']
@property
def profile(self):
# this runs with hasattr
return self.master.google_plus_service.people().get(userId='me').execute()
Run Code Online (Sandbox Code Playgroud)
运行以下代码调用profile属性并实际进行调用:
#Check if the call is an attribute
if not hasattr(google_plus_user, call):
self.response.out.write('Unknown call')
return
Run Code Online (Sandbox Code Playgroud)
为什么?如何在不拨打api电话的情况下解决这个问题?