ImportError:无法从“textstat.textstat”导入名称“legacy_round”

问题描述 投票:0回答:2

我正在尝试从

legacy_round
导入
textstat
如下:

from textstat.textstat import textstatistics,legacy_round

但我收到以下错误:

ImportError: cannot import name 'legacy_round' from 'textstat.textstat'

知道如何解决这个问题吗?

python nlp importerror readability
2个回答
0
投票

legacy_round 已从最新版本中删除,您可能使用的是旧版本。

您可以尝试将 textstat 包降级到包含它的版本:

pip install textstat==0.6.2

或者您可以使用 Python 标准库中的 round 函数代替 legacy_round:

from textstat.textstat import textstatistics
import math


flesch_reading_ease = textstatistics().flesch_reading_ease(text)
flesch_reading_ease_rounded = math.floor(flesch_reading_ease + 0.5)

0
投票

根据 (#186) 中的@alxwrd,您需要使用

_legacy_round
而不是
legacy_round
.

from textstat.textstat import textstatistics

#add these two lines
from textstat import textstat
legacy_round = textstat._legacy_round
© www.soinside.com 2019 - 2024. All rights reserved.