[Tutor] csv.reader: bad argument type
tetsuo2k6 at web.de
tetsuo2k6 at web.de
Wed Jan 23 14:43:12 CET 2008
Kent Johnson schrieb:
> tetsuo2k6 at web.de wrote:
>
>> 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).
>
> It doesn't seem to get as far as actually reading the file.
>
>> 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?
>
> csv.reader is not built-in, that is correct. But it is implemented in C
> so you won't get a good traceback into where the failure is actually
> occurring.
>
> What version of Python is on the two machines?
I guess that's it - my client has 2.5 while the server runs 2.4 ... I
don't think any differences are mentioned in the library reference for
csv but I'll have a second look.
> A couple of things to try, maybe some hints will come out:
> - print the value of datei just to make sure nothing funny there
Filename is alright - my.csv
> - split the open to a separate line to make sure it is the call to
> reader that is the problem:
> f = open(datei, "rb")
> reader = csv.reader(f, delimiter = ";", quotechar = "", quoting =
> csv.QUOTE_NONE)
Same result. Thanks nonetheless :)
> Kent
>
- Paul
More information about the Tutor
mailing list