我有一个看起来像这样的文本文件
fpath_1_a.txt fpath_1_b.txt
fpath_2_a.txt fpath_2_b.txt
fpath_3_a.txt fpath_3_b.txt
fpath_4_a.txt fpath_4_b.txt
两列中的字符串是指向不同文件的路径。我想阅读这个文本文件,这样我就可以遍历各个行,并且在每次迭代中我都有一个包含path_a和path_b的字符串,这样我就可以读取相应的文件了。 我该怎么做?
答案 0 :(得分:0)
试试这个。
sep = " "
filename = "your text file name"
with open(filename) as fp:
for line in fp:
for fname in line.split(sep):
with open(fname) as gp:
print gp.read()/* do something */