python gensim:AttributeError:“list”对象没有attribu

2024-09-28 19:31:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个小python管道。一个类清理和柠檬化数据。 它返回字符串列表(即List[List[str]])。然后我将列表传递给另一个类,这个类将数据传递给gensim字典

但是,以下代码引发此异常:

dictionary = corpora.Dictionary(self.bowlist)
AttributeError: 'list' object has no attribute 'bowlist'

代码:

^{pr2}$

我是Python新手,但是我已经检查过debug和其他方法,bowlist是一个List[List[str]]。在


Tags: 数据字符串代码self列表dictionary字典管道
1条回答
网友
1楼 · 发布于 2024-09-28 19:31:10

你这样用吗?在

ListOfListsToGensimCorpora.perform(bow_list)

这很好:

^{pr2}$

或者用这个改变你的代码?在

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)

相关问题 更多 >