用计数器迭代文件名 [英] Iterate file name with counter
本文介绍了用计数器迭代文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在基于字符串拆分文件,并且希望对输出文件名进行编号。
I'm splitting a file based on a string, and would like to have the output file names be numbered.
这是我到目前为止所拥有的:
This is what I have so far:
outputfile = open("output.seq")
outputfileContent = outputfile.read()
outputfileList = outputfileContent.split(">")
for count, line in enumerate(f):
for items in outputfileList:
seqInfoFile = open('%f.dat', 'w')
seqInfoFile.write(str(items))
我不确定在哪里定义f。
I'm not sure where to define f.
谢谢您的帮助!
推荐答案
假设我没有
outputfile = open("output.seq")
outputfileContent = outputfile.read()
outputfileList = outputfileContent.split(">")
for count, content in enumerate(outputfileList, 1):
with open("output_%s.dat" % count, "w") as output:
output.write(content)
这篇关于用计数器迭代文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文