2

In what cases would Python throw this error:

"TypeError: bad argument type for built-in operation"

The error was reported in this line of code:

csv.reader(open(file_name), dialect=dialect)

I've tried to reproduce it but the closest I got was this error:

"TypeError: coercing to Unicode: need string or buffer, bool found"

I've tried with Python2.7 and Python 2.5 on Linux and Python 2.4 on Windows XP

4

2 回答 2

3

The csv.reader in Python 2.4 has known bugs; see http://mail.python.org/pipermail/tutor/2008-January/059758.html

In general, "bad argument type for built-in operation" crops up all over the place because it's the exception text generated by PyErr_BadArgument CPython API call. This means that the traceback won't be much use because the exception is raised in C code. Your best bet for debugging is to run Python under a debugger and set a breakpoint on PyErr_BadArgument.

于 2012-07-10T15:42:06.053 回答
0

我的猜测是这file_name是一个布尔值,而不是像open()预期的字符串或缓冲区。我不会很关心不同的信息。它们都是 TypeErrors,一个恰好比另一个更具体,可能是因为 Python 版本的一些差异。

于 2012-07-10T15:30:02.693 回答