相关疑难解决方法(0)

为什么hasattr执行@property装饰器代码块

在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电话的情况下解决这个问题?

python properties python-2.7

6
推荐指数
2
解决办法
1762
查看次数

标签 统计

properties ×1

python ×1

python-2.7 ×1