Python 3 experience with textstat / readability

is anyone here who has ever used readability 0.2 or textstat 0.3.1 in python? Could not find anything on SO dedicated to this issue or any good documentation on this.

So far, my code is: It iterates through a bunch of txt files locally stored and prints the result (readability indicators) to the main text file.

from textstat.textstat import textstat
import os
import glob
import contextlib


@contextlib.contextmanager
def stdout2file(fname):
    import sys
    f = open(fname, 'w', encoding="utf-8")
    sys.stdout = f
    yield
    sys.stdout = sys.__stdout__
    f.close()


def readability():
        os.chdir(r"F:\Level1\Level2")
        with stdout2file("Results_readability.txt"):
                for file in glob.iglob("*.txt"):  # iterates over all files in the directory ending in .txt
                        with open(file, encoding="utf8") as fin:
                                contents = fin.read()
                                if __name__ == '__main__':
                                        print(textstat.flesch_reading_ease(contents))
                                        print(file.split(os.path.sep)[-1], end=" | ")
                                        print(textstat.smog_index(contents), end="\n ")
                                        print(file.split(os.path.sep)[-1], end=" | ")
                                        print(textstat.gunning_fog(contents), end="\n ")

This works very well, however I have two problems:

.

+4
2

, textstat . : , , . "No.":

In: textstat.flesch_kincaid_grade("No.")
Out: -4.6

-3.4 ( 0,39 * 1 + 11,8 * 1-15,59)

+1

, , : "F:\Level1\Level2\Results_readability.txt" "..\Other\Results_readibilty.txt"

. YMMV. . , , , , .

, , , , , , . , textstat . , , .

0

Source: https://habr.com/ru/post/1654839/


All Articles