zhibengyanlou474
zhibengyanlou474
2016-05-04 11: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条回答