CSV语法错误?

时间:2013-07-08 14:33:06

标签: python

只是想知道是什么触发了这种语法错误:

  File "/Users/samuelfinegold/Documents/noodle/add_col.py", line 16

                                                 ^
SyntaxError: invalid syntax
logout

[Process completed]

脚本:

import csv

# fieldnames = ['name','degrees','area','phone','email','website']

with open('ieca_first_col_fake_text.txt', 'r') as input:
    with open('new_col.txt', 'w') as output:
        writer = csv.writer(output)
        for row in csv.reader(input):
            writer.writerow(row+['Berry'])
            writer.writerow(row.append('new_col')

# with open('ieca_first_col_fake_text.txt','r') as input:
#     with open('new_col_dict.txt','w') as output:
#         dict_writer = csv.DictWriter(output, fieldnames, delimiter = '\t')
#         dict_reader = csv.DictReader(input)

谢谢!

1 个答案:

答案 0 :(得分:3)

你错过了这一行的结束)

writer.writerow(row.append('new_col')
                                     ^         
                                     |