擅长:python、mysql、java
<pre><code>import csv
data = [('01', ['name abc', 'age 32', 'address addr123']), ('02', ['name def', 'age 22', 'address addr456 789'])]
with open(path_to_csv, 'w') as csv_file:
writer = csv.DictWriter(csv_file, 'id name age address'.split())
writer.writeheader()
for row_id, rest in data:
row = {'id': row_id}
for item in rest:
key, value = item.split(' ', maxsplit=1)
row[key] = value
writer.writerow(row)
</code></pre>