So, somethig easy this time... reading lines of text from files in a directory...
1) Import the os module
import os
2) loop into the files, but only txt files
for files in os.listdir(): if files.endswith(".txt"):
3) loop the lines and print them
with open(files) as txt: for eachline in txt.readlines(): print(eachline)
and then, running the script (if you're in jupyter notebook, hit ctrl+enter) you will see all the lines of all your txt files one after another... what this could be useful for... ? I will leave that to the imagination of the readers.
Comments
Post a Comment