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

399 views Asked by At

I am trying to import legacy_round from textstat as follows:

from textstat.textstat import textstatistics,legacy_round

But I get following error: ImportError: cannot import name 'legacy_round' from 'textstat.textstat'

Any idea how can fix this?

2

There are 2 answers

0
Abdulmajeed On

legacy_round was removed from recent version and it is possible you are using an older version.

You could try downgrading the textstat package to a version that includes it:

pip install textstat==0.6.2

Or you can use the round function from the Python standard library instead of 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
Timeless On

According to @alxwrd in (#186), you need to use _legacy_round instead of legacy_round.

from textstat.textstat import textstatistics

#add these two lines
from textstat import textstat
legacy_round = textstat._legacy_round