装饰器的静态方法

时间:2019-07-18 06:32:57

标签: python python-3.x

我想用静态方法制作装饰器,得到TypeError: 'staticmethod' object is not callable

这是我的静态方法

@staticmethod
def error_handling(func):

    try:
        func()
    except KeyError:
        return 'Appid does not exist'
    except KeyboardInterrupt:
        return 'User canceled the operation '

以及我的装饰器示例

@error_handling
def type(self, appid):  # This method will return an appid's type (game or dlc)

    """
    This method will return an appid's type (game or dlc)

    :param appid: str or int
    :return: str
    """
    response = self.get_request(appid)
    return response.json()[f'{appid}']['data']['type']

0 个答案:

没有答案