[Tutor] csv.reader: bad argument type

tetsuo2k6 at web.de tetsuo2k6 at web.de
Wed Jan 23 13:32:57 CET 2008


I don't get this.

I wrote a script that reads data from a .csv file and puts them into a 
MySQL database. It works fine on my machine.

Here's the relevant part:


<snip>
import csv
import MySQLdb
import sys

try:
         datei = sys.argv[1]
except:
         print("Usage: insert_into_db <.csv-file>")

# convert csv to list
reader = csv.reader(open(datei, "rb"), delimiter = ";", quotechar = "", 
quoting = csv.QUOTE_NONE)
</snip>

After copying it to the server, it says:

server1:/usr/local/sbin# ./insert_dgf_customers.py /usr/local/sbin/my.csv
Traceback (most recent call last):
   File "./insert_dgf_customers.py", line 27, in ?
     reader = csv.reader(open(datei, "rb"), delimiter = ";", quotechar = 
"", quoting = csv.QUOTE_NONE)
TypeError: bad argument type for built-in operation


The file my.csv is a test file and correctly formatted (it's the same 
file that worked on the other machine).
I thought the built-in operation meant here is open(), but without 
putting csv.reader() around it everything works fine... And I guess 
csv.reader is _not_ built-in, for it from the module - is that correct?

Any hints?

-paul


More information about the Tutor mailing list