I have several text files that I want to conceneate to one big string. The text files are in the same folder as my jupyter notebook file. I found this solution online, but I have problems understanding it right. It goes like this:
def read_files_into_string(filenames):
strings = []
for filename in filenames:
with open(f'textfile_{filename}.txt') as f:
strings.append(f.read())
return '\n'.join(strings)
I understand that we define the function first, than we create an empty stringfile. After this we open our textfiles, say, textfile_1 to textfile_10 as f (a variable?), one after another with a loop.
Now to the part I don't get: Do we read the files (f.read) one after antoher and append it to the string file?
But the part that puzle me the most is the return statement in the end: What's the use of the new line expression '\n'? My text files end with new lines - are we gluing the seperate "strings" together with this character?