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>
  File "C:\Python26\lib\csv.py", line 149, in writerows
  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'}

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

Thanks in advance.

Recommended Answers


For further information, take a look, at this thread ...


Jump to Post

All 2 Replies

Okay - I got it ...


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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.