zhibengyanlou474 2016-05-04 11:23 采纳率: 0%
浏览 5639

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条回答 默认 最新

  • Robot-C 2016-05-04 11: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,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题