2013-07-08 50 views
0

只是想知道什麼觸發此語法錯誤:CSV語法錯誤?

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) 

謝謝!

+0

而且,什麼是線16? – djechlin

+0

這是一個很好的問題......猜測他們認爲這是comp認爲我通過不關閉括號 – goldisfine

+0

oic而進入的下一行。文件末尾的語法錯誤通常是由於丟失了大括號或右括號引起的。 – djechlin

回答

3

你錯過了在這條線收盤)

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

剛剛實現!謝謝。將在一秒鐘內接受。 – goldisfine

+0

有沒有機會知道如何添加製表符分隔的列? http://stackoverflow.com/questions/17528274/add-column-to-a-tab-delimited-text-file – goldisfine