一旦建立了目录,有没有办法在Python中使用Unix中的cat函数或类似的函数?我想将 files_1-3 合并到 merged.txt
我通常会在 Unix 中找到该目录,然后运行
cat * > merged.txt
file_1.txt
file_2.txt
file_3.txt
merged.txt
Use the fileinput http://docs.python.org/2/library/fileinput.html module:
import fileinput
import glob
with open('/path/to/merged.txt', 'w') as f:
for line in fileinput.input(glob.glob('/path/to/files/*')):
f.write(line)
fileinput.close()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)