Python 仅将部分列表导出为 CSV

Python export only parts of list to CSV

请你帮忙。 使用 Python 2.6.6.

我有一个名为 'results' 的列表,例如:

# This is remark only: Type for `results`: <type 'list'>
1 86561198961563884 430cf63c640accf1c90ed2a9fe2ccce4
2 86561198160451905 d3fe1c990841552483955dfa81234338
3 86561198114921980 099c88e5c344233a388c0e558d3d88c8
4 86561198160858321 85cf9fa846e0f626c2490d12e9c9919e

当前正在写入文件 'myOutput.csv',代码为:

import csv
with open("myOutput.csv", "wb") as csvfile:
    writer = csv.writer(csvfile)
    writer.writerows(results)

我想要这个在 csv 文件中:{因此不是 "first column" / 行 [0]}

86561198961563884 430cf63c640accf1c90ed2a9fe2ccce4
86561198160451905 d3fe1c990841552483955dfa81234338
86561198114921980 099c88e5c344233a388c0e558d3d88c8
86561198160858321 85cf9fa846e0f626c2490d12e9c9919e

背景和原因。 已更改列表。
现在需要转至 CSV 以进行 MySQL 导入。

谢谢,

Slice 每行第一项。

writer.writerows([line[1:] for line in results])

[1:]表示从索引为1的元素开始切片,也就是第一项,一直到最后。这构成了 的一部分,它为每一行执行此切片,创建一个新的 list 并发送到 writer.writerows