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"):
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:
.