[issue5455] csv module no longer works as expected when file opened in binary mode

Jervis Whitley report at bugs.python.org
Mon Mar 9 04:01:04 CET 2009


Jervis Whitley <jervisau at gmail.com> added the comment:

in _csv.c, the check is done here:

lineobj = PyIter_Next(self->input_iter);
   if (lineobj == NULL) {
      /* End of input OR exception */
      if (!PyErr_Occurred() && self->field_len != 0)
         PyErr_Format(error_obj,
            "newline inside string");
         return NULL;
      }
if (!PyUnicode_Check(lineobj)) {
   PyErr_Format(error_obj,
      "iterator should return strings, "
      "not %.200s "
      "(did you open the file in text mode?)",
      lineobj->ob_type->tp_name
   );
   Py_DECREF(lineobj);
   return NULL;
}

So the returned lineobj is a bytes type and then the PyUnicode_Check
throws the error.

----------
message_count: 1.0 -> 2.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5455>
_______________________________________


More information about the Python-bugs-list mailing list