28 对象的封装并返回值

常用与ajax数据返回:

class BaseResponse(object):
    def __init__(self, status=False, detail=None, data=None):
        self.status = status
        self.detail = detail
        self.data = data
    
    @property
    def dict(self):
        return self.__dict__

obj = BaseResponse(status=True)
print(obj.dict)  #  {'status': True, 'detail': None, 'data': None}
posted @ 2022-10-05 10:29  角角边  Views(14)  Comments(0Edit  收藏  举报