[issue18829] csv produces confusing error message for unexpected string encoding

Thibault Kruse report at bugs.python.org
Sun Aug 25 14:56:23 CEST 2013


New submission from Thibault Kruse:

To reproduce

$ python --version
Python 2.7.3
$ python -c 'from __future__ import unicode_literals; import csv; reader = csv.reader("foo", delimiter=",")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: "delimiter" must be an 1-character string

This is confusing because "," is like a 1-character (unicode) string, while csv requires a 1-character (byte) string. In python3, it's the inverse problem, using bytestring b','

$ python3 --version
Python 3.2.3
$ python3 -c 'import csv; reader = csv.reader("foo", delimiter=b",")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: "delimiter" must be an 1-character string


So I believe csv should state more clearly what went wrong here in each case, or what kind of string csv is willing to accept in the respective python version.

Whether the python3 refusal to use a bytestring is even reasonable I don't know.

This might or might not be related to the issue of multichar delimiters: http://bugs.python.org/issue15158  (just sayin)

----------
components: Library (Lib)
messages: 196126
nosy: Thibault.Kruse
priority: normal
severity: normal
status: open
title: csv produces confusing error message for unexpected string encoding
type: behavior
versions: Python 2.7, Python 3.2

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


More information about the Python-bugs-list mailing list