【发布时间】:2017-06-04 20:59:06
【问题描述】:
假设我的目录中有n 文件,文件名:file_1.txt, file_2.txt, file_3.txt .....file_n.txt。我想将它们单独导入Python,然后对它们进行一些计算,然后将结果存储到n对应的输出文件中:file_1_o.txt, file_2_o.txt, ....file_n_o.txt.
我已经弄清楚如何导入多个文件:
import glob
import numpy as np
path = r'home\...\CurrentDirectory'
allFiles = glob.glob(path + '/*.txt')
for file in allFiles:
# do something to file
...
...
np.savetxt(file, ) ???
不太清楚如何在文件名后面附加_o.txt(或任何字符串),以便输出文件为file_1_o.txt
【问题讨论】:
标签: python import export filenames