Skip to main content
 首页 » 编程设计

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

2024年08月30日33mq0036

在什么情况下 Python 会抛出这个错误:

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

这行代码报错:

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

我试图重现它,但最接近的是这个错误:

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

我试过在 Linux 上使用 Python2.7 和 Python 2.5,在 Windows XP 上使用 Python 2.4

请您参考如下方法:

Python 2.4 中的csv.reader 有已知错误;见http://mail.python.org/pipermail/tutor/2008-January/059758.html

通常,“内置操作的错误参数类型”到处都是,因为它是由 PyErr_BadArgument 生成的异常文本CPython API 调用。这意味着回溯不会有多大用处,因为异常是在 C 代码中引发的。调试的最佳选择是在调试器下运行 Python 并在 PyErr_BadArgument 上设置断点。