Hi,
I have a quick, and what seems like very stupid question.
I have a list of files in a directory with various extensions. I want to open only the ones with the extension '.txt'.
I have got as far as finding them (and can print their filenames to a new file) but don't seem to be able to open the files themselves to extract their data. Here is the code I have so far:
import os
writer=open('psub', 'w')
writer.close()
for files in os.listdir('.'):
if files.endswith('.txt'):
writer=open('psub', 'a')
print(files, file=writer)
writer.close()
How then, do I go on to open and read the '.txt' files?
Any pointers would be very appreciated...
Cheers