【发布时间】:2011-12-05 02:49:39
【问题描述】:
当我检查我的 Excel 文件时,它只写入最后输入的一行数据。
def Table(fn,fe):
for fseq in fn:
count=0
for k in fseq:
if k=='G' or k=='C':
count=count+1
percentage=(float(count)/len(fseq))*100
fin=open(fe,'w')
table=str(fseq)+'\t'+str(count)+'\t'+str(percentage)+'\n'
fin.write(table)
return fe
tablist=["AAUG","GCGA","AGCG","TCGA"]
fout=Table(tablist, 'abc.xls')
应该是这样输出的:
AAUG 1 25.0
GCGA 3 75.0
AGCG 3 75.0
TCGA 2 50.0
相反,我的输出如下所示:
TCGA 2 50.0
并返回正在写入的文件的名称。
为什么只为字符串的最后一个元素写入数据?
【问题讨论】:
-
请正确格式化您的代码。
-
为什么不使用openpyxl?
标签: python string function export-to-excel