c - python中数据模型,以下两种声明方式有什么区别

查看:77
本文介绍了c - python中数据模型,以下两种声明方式有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

class SearpcClient(object):

    def call_remote_func_sync(self, fcall_str):
        raise NotImplementedError()
        
        
class RpcClientBase(SearpcClient):
    
    def __init__(self, ccnet_client_pool, service_name, retry_num=1,
                 is_remote=False, remote_peer_id='', req_pool=False):
        SearpcClient.__init__(self)
        self.pool = ccnet_client_pool
        self.service_name = service_name
        self.retry_num = retry_num
        self.is_remote = is_remote
        self.remote_peer_id = remote_peer_id
        self.req_pool = req_pool
        if self.is_remote and len(self.remote_peer_id) != 40:
            raise ValueError("Invalid remote peer id")
            
            
class User(object):
    is_staff = False
    is_active = False
    is_superuser = False
    groups = []
    org = None
    objects = UserManager()

解决方案

简单说,一个是类数据属性,一个是对象属性。

复杂说,你需要好好看看 class 部分,下面是我整理的一些资料:

https://github.com/xuelangZF/CS_Offer/blob/master/More/Python_Class.md

还可以看 Python Cookbook:

http://python3-cookbook.readthedocs.io/zh_CN/latest/chapters/p08_classes_and_objects.html

你可能还需要点 面向对象 的常识!

这篇关于c - python中数据模型,以下两种声明方式有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆