I now have a file with a list of file paths. I want to loop open them to read and write. Can anyone suggest how to do this? Everything I have seen so far is only to read these lines and print them out, I want my code to open these paths. Below is a slice of the path file:
E:\Grad\LIS\LIS590 Text mining\Part1\Part1\awards_1994\awd_1994_96\a9496340.txt
E:\Grad\LIS\LIS590 Text mining\Part1\Part1\awards_1994\awd_1994_96\a9496341.txt
E:\Grad\LIS\LIS590 Text mining\Part1\Part1\awards_1994\awd_1994_96\a9496342.txt
E:\Grad\LIS\LIS590 Text mining\Part1\Part1\awards_1994\awd_1994_96\a9496343.txt
E:\Grad\LIS\LIS590 Text mining\Part1\Part1\awards_1994\awd_1994_96\a9496344.txt
E:\Grad\LIS\LIS590 Text mining\Part1\Part1\awards_1994\awd_1994_96\a9496345.txt
E:\Grad\LIS\LIS590 Text mining\Part1\Part1\awards_1994\awd_1994_96\a9496346.txt
E:\Grad\LIS\LIS590 Text mining\Part1\Part1\awards_1994\awd_1994_96\a9496347.txt
E:\Grad\LIS\LIS590 Text mining\Part1\Part1\awards_1994\awd_1994_96\a9496348.txt
E:\Grad\LIS\LIS590 Text mining\Part1\Part1\awards_1994\awd_1994_96\a9496349.txt
E:\Grad\LIS\LIS590 Text mining\Part1\Part1\awards_1994\awd_1994_96\a9496350.txt
E:\Grad\LIS\LIS590 Text mining\Part1\Part1\awards_1994\awd_1994_96\a9496351.txt
...
This is the code I am trying:
def work_on(r'E:\Grad\LIS\LIS590 Text mining\file+test.txt'): # The last quotation mark gives me that error. I also tried double quotation mark, didn't work either.
with open(r'E:\Grad\LIS\LIS590 Text mining\file+test.txt', 'r') as data_file:
with open('file_list.txt', 'r') as file_list: #file_list.txt is the file name I saved all the paths.
for filename in file_list:
with open(filename, 'r') as data_file:
work_on(filename)