I’ve just uploaded this CSV file via a form, POSTing it to my Python CGI script. The upload seems to have completed successfully. Permissions on the folder are 777, on the file are 755.
>>> import csv
>>> csvHandle = open('files/TestData.csv', "rb")
>>> csvRawRecordDicts = csv.DictReader(csvHandle)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: __init__() takes at least 3 arguments (2 given)
The values are as follows:
csvRawRecordDicts undefined,
csv = <module 'csv' from '/usr/lib/python2.3/csv.pyc'>,
csv.DictReader = <class csv.DictReader>,
csvHandle = <open file 'files/TestData.csv', mode 'rb'>
The code works fine on my local computer with Python 2.5. The error happens on 2.3.
What is the thought-process for debugging something like this? Where do I begin looking?
There are a couple of things you could be doing:
DictReaderrequires two arguments at least, while you’re passing one>>> help(csv.DictReader)and arrive to the same conclusion.As reading of the docs might explain second of the arguments should be
fieldnames(I presume list will suffice), importantly this information was conveyed in the error message!