目前我有这个:
2个变量: varHeader:ExtraColumn varContent:ToBeFilledIn
writer.writeheader()
for line in reader:
writer.writerow(line)
一切正常。问题是我有2个变量,varHeader和varContent。我失败了:
虽然这对我来说似乎很简单,但它让我大吃一惊,我无法完成它。猜猜这是一种典型的星期五疾病; - )
感谢队友,
来自新手。
答案 0 :(得分:2)
这是你想要的吗?
from csv import DictReader, DictWriter
with open ...:
reader = DictReader(in_f)
writer = DictWriter(out_f, ['ExtraColumn'] + reader.fieldnames)
writer.writeheader()
for line in reader:
line['ExtraColumn'] = varContent
writer.writerow(line)