2 zhibengyanlou474 zhibengyanlou474 于 2016.05.04 19:23 提问

python问题: AttributeError

python 报错: AttributeError: class BaseEntity has no attribute '__class__'
BaseEntity继承的时候报错没有__class__属性(新手,见谅)

源代码如下:

class BaseEntity:
@classmethod
def load(clazz,index):
return clazz.objects[index]

@classmethod
def loadField(clazz,index,field):
    return getattr(clazz.objects[index], field)


@classmethod
def updateField(clazz,index,field,value):
    obj=clazz.objects[index]
    setattr(obj, field, value)
    obj.save()


@classmethod
def insert(clazz,entity):
    res=clazz.objects(eid=entity.eid)
    if len(res)==0:
        entity.save()
        return True
    else:
        entity.index=res[0].index
        return False

@classmethod
def persist(clazz,entity):
    '''
    :summary :更新id相同的,如果没有则插入
    :param clazz:
    :param entity:
    '''
    queryResult=clazz.objects(eid=entity.eid)
    if len(queryResult)==0:
        entity.save()
    else:
        entity.index=queryResult[0].index
        queryResult[0].delete()
        entity.save()

@classmethod
def delete(clazz,entity):
    queryResult=clazz.objects(eid=entity.eid)
    if len(queryResult)>0:
        queryResult[0].delete()

class Article(Document,BaseEntity):
eid=StringField(max_length=20,required=True)
index=LongField()
title=StringField(default=None)
content=StringField(default=None)
publistDate=DateTimeField(default=None)
wordList=ListField(StringField())
topicVector=ListField(FloatField())

2个回答

devmiao
devmiao   Ds   Rxr 2016.05.05 07:27
zhibengyanlou474
zhibengyanlou474 好像不太一样吧
一年多之前 回复
CSDNXIAOC
CSDNXIAOC   2016.05.04 19:31

>>> m=re.match(r'WwW.(.*)..{3}','www.python.org')
>>> m.group(1)
Traceback (most recent call last):
  File "<pyshell#32>", line 1, in <module>
&nbs......
答案就在这里:Python:AttributeError: 问题
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!