0

hey folks,
i'm trying myself on a csv based adressbook but I get the following error:

Traceback (most recent call last):
  File "C:\Dokumente und Einstellungen\Mo\Desktop\adressbook.py", line 11, in <module>
    writer.writerows(data)
  File "C:\Python26\lib\csv.py", line 149, in writerows
    rows.append(self._dict_to_list(rowdict))
  File "C:\Python26\lib\csv.py", line 140, in _dict_to_list
    ", ".join(wrong_fields))
ValueError: dict contains fields not in fieldnames:L,a,s,t,n,a,m,e

This is my code so far:

import csv

reader = csv.DictReader(open('adress.csv', 'rb'))

for row in reader:
    print row

writer = csv.DictWriter(open('adress1.csv', 'wb'), ['Firstname', 'Lastname', 'Phone'])
writer.writerow({'Firstname' : 'Firstname', 'Lastname' : 'Lastname', 'Phone' : 'Phone'})
data = {'Firstname' : 'Carl', 'Lastname' : 'Johnson', 'Phone' : '987651'}
writer.writerows(data)

I don't know what the error message is trying to tell me...
Do you get something out of it?

Thanks in advance.

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by J-M DESMETTRE
0

Okay - I got it ...

writer.writerows(data)

If you want to add a single row the method is called 'writerow'

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.