zhibengyanlou474
2016-05-04 11:23python问题: 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条回答
为你推荐
- Python问题 出现问题报错怎么办?
- python
- 1个回答
- python报错:requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(10060, 'WSAETIMEDOUT')"))
- python
- 开发语言
- 2个回答
- 求助,python 报错:AttributeError: module 'log0' has no attribute 'out'怎么办?
- python
- 开发语言
- 2个回答
- 新人使用pycharm运行飞机大战项目报如下错误:AttributeError: module 'pygame.image' has no attribute 'get_rect'
- python
- 开发语言
- 1个回答
- AttributeError: 'DataFrame' object has no attribute 'itemtype'
- python
- 3个回答
换一换