Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I have directory with different text files of stop words, i want to import them all togather so that it can read with (with open)

file_list = glob.glob(os.path.join(os.getcwd(), "Directory", "*.txt"))

corpus = []

for file_path in file_list:

    with open(file_path,'r') as stop_words:
        stop_words.append(stop_words.read())
stopWords = stop_words.read().lower()
stopWordList = stopWords.split('\n')
stopWordList[-1:] = []    

AttributeError: ‘_io.TextIOWrapper’ object has no attribute ‘append’

Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here is one way to get all words into a list.

file_list = glob.glob(os.path.join(os.getcwd(), "Directory", "*.txt"))

stopwords = []

for file_path in file_list:
    with open(file_path, 'r') as f:
        stopwords.extend(f.read().lower().splitlines())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading