I have a folder full of text documents, the text of which needs to be loaded into a single list variable.
Each index of the list, should be the full text of each document.
So far I have this code, but it is not working as well.
dir = os.path.join(current_working_directory, 'FolderName')
file_list = glob.glob(dir + '/*.txt')
corpus = [] #-->my list variable
for file_path in file_list:
text_file = open(file_path, 'r')
corpus.append(text_file.readlines())
text_file.close()
Is there a better way to do this?
Edit: Replaced the csv reading function (read_csv
) with text reading function (readlines()
).