[英]DocumentStore TypeError | Python
Update, I now get a TypeError on the last line 21.更新,我现在在最后一行 21 上得到一个 TypeError。
So, if I make capacity = 2
, and add 1
document:因此,如果我让
capacity = 2
并添加1
文档:
document_store = DocumentStore(2)
document_store.add_document("document")
print(document_store)
It should return:它应该返回:
Document store: 1/2
class DocumentStore(object):
def __init__(self, capacity):
self._capacity = capacity
self._documents = []
@property
def capacity(self):
return self._capacity
@property
def documents(self):
return self._documents
def add_document(self, document):
if(len(self._documents) >= self._capacity): # >=
raise Exception('Document store is full')
self._documents.append(document)
def __repr__(self):
return "Document store: " + len(self._documents) + "/" + self._capacity # ERROR!
Update, I now get a TypeError on the last line 21.更新,我现在在最后一行 21 上得到一个 TypeError。
So, if I make capacity = 2
, and add 1
document:因此,如果我让
capacity = 2
并添加1
文档:
document_store = DocumentStore(2)
document_store.add_document("document")
print(document_store)
It should return:它应该返回:
Document store: 1/2
class DocumentStore(object):
def __init__(self, capacity):
self._capacity = capacity
self._documents = []
@property
def capacity(self):
return self._capacity
@property
def documents(self):
return self._documents
def add_document(self, document):
if(len(self._documents) >= self._capacity): # >=
raise Exception('Document store is full')
self._documents.append(document)
def __repr__(self):
return "Document store: " + len(self._documents) + "/" + self._capacity # ERROR!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.