This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: csv error name incorrect
Type: behavior Stage:
Components: None Versions: Python 2.6, Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: kitterma, skip.montanaro
Priority: normal Keywords:

Created on 2010-01-16 05:15 by kitterma, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg97864 - (view) Author: Scott Kitterman (kitterma) Date: 2010-01-16 05:15
Using the csv module I encountered an ASCII NUL in a file and got this error:

"_csv.Error: line contains NULL byte"

According to the documentation ( http://docs.python.org/library/csv.html#module-contents ) it should be csv.Error:.  Attempting to trap the error using try:/except _csv.Error: does not work.  It needs to be except csv.Error:.
msg97881 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2010-01-16 15:36
This is to be expected.  The Error Exception is actually defined in the
underlying _csv extension module.  The higher level csv Python module
imports it.  The two are the same object:

>>> import csv, _csv
>>> csv.Error
<class _csv.Error at 0x818517c>
>>> _csv.Error
<class _csv.Error at 0x818517c>
>>> csv.Error is _csv.Error
True

So, continue to use

    try:
       ...
    except csv.Error:
       ...

and ignore the leading underscore.
History
Date User Action Args
2022-04-11 14:56:56adminsetgithub: 51960
2010-01-16 15:36:31skip.montanarosetstatus: open -> closed

nosy: + skip.montanaro
messages: + msg97881

resolution: not a bug
2010-01-16 05:15:19kittermacreate