Python,CSV和Excel:与信息并排创build一个文本文件

我想让这个代码将一个文本文件与信息并列作为列,但现在它显示为行。

如果你想在这里完整的代码是我的pastebin:

http://pastebin.com/TeD78wQn

with open('file.txt','wb') as fou: writer = csv.writer(fou) for row in data: writer.writerow(row) 

我想这是你想要的:

 transposed = zip(*data) with open('col_output.txt','wb') as fou: writer = csv.writer(fou) for row in transposed: writer.writerow(row) 

编辑:从原始数据中删除空格,只需在填充data时调用.strip()

 data = [] data.append([sheet.cell_value(row, 0).strip() for row in range(sheet.nrows)]) data.append([sheet.cell_value(row, 1).strip() for row in range(sheet.nrows)])