通过Python 2.7在.xls中写入多个列

时间:2011-12-10 05:07:14

标签: python file excel

    out_file.write('Position'+'\t'+'Hydrophobic'+'\n')

    for i in position:
        out_file.write(str(i)+'\n')
    for j in value:
        out_file.write('\t'+str(j)+'\n')

所以它说

Position     Hydrophobic
0            a
1            b
2            c

#... and so on

当它写入excel文件时,它将j的值放在位于列的i列的底部

如何将它们与'\ t'和'\ n'并排放在一起?

1 个答案:

答案 0 :(得分:2)

for i, j in zip(position, value):
    out_file.write(str(i) + '\t' + str(j) + '\n')

或更好:

     out_file.write('%s\t%s\n' % (str(i), str(j))

或更好:

text = ['%s\t%s' % (str(i), str(j) for i, j in zip(position, value)]
text = '\n'.join(text)
out_file.write(text)