我有一些生成整数和str的代码,我可以将它们附加到列表中,但我希望它们在每个int和str的单独行上。我的代码如下:
responses = []
responses.append(respTime)
responses.append(category_repeated)
responses = [0.11700010299682617 correct 0.1000001431 correct 0.0779998302 correct]
我希望这样,可以将libreOffice calc打开成两列的行:
0.117000 correct
0.100000 correct
提前感谢任何建议。
答案 0 :(得分:2)
如果你有一个元组列表,它会更容易处理:
responses = []
responses.append((respTime, category_repeated)) # <--- slight difference
responses == [(0.11700010299682617, 'correct'), (0.1000001431, 'correct')]
# responses[0] == (0.11700010299682617, 'correct')
以下是从docs编写.csv文件的示例:
import csv
with open('eggs.csv', 'wb') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=' ',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])
spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])