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 in位置列的底部
如何将它们与“\t”和“\n”并排放置?
最佳答案
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)
关于python - 通过 Python 2.7 在 .xls 上写入多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8454543/