我有一个小的python管道。一类清除数据并对其进行定形。
它返回一个字符串列表列表(即List[List[str]]
)。然后,我将列表传递给另一个类,该类将数据传递给gensim字典
但是,以下代码引发此异常:
dictionary = corpora.Dictionary(self.bowlist)
AttributeError: 'list' object has no attribute 'bowlist'
代码:
from typing import List
import re
from gensim import corpora
class ListOfListsToGensimCorpora:
def __init__(self, bow_list: List[List[str]]):
self.bowlist = bow_list
def perform(self):
dictionary = corpora.Dictionary(self.bowlist)
print(dictionary)
我是Python的新手,但是我已经通过调试和其他方法进行了检查,bowlist是一个List [List [str]]。
答案 0 :(得分:1)
您正在那样使用吗?
ListOfListsToGensimCorpora.perform(bow_list)
这很好:
l = ListOfListsToGensimCorpora(bow_list)
l.perform()
还是以此更改您的代码?
from typing import List
import re
from gensim import corpora
class ListOfListsToGensimCorpora:
def __init__(self, bow_list: List[List[str]]):
self.bowlist = bow_list
self.perform() # run perform when instantiuation
def perform(self):
dictionary = corpora.Dictionary(self.bowlist)
print(dictionary)