[ python-Bugs-1599055 ] csv module does not handle '\x00'

SourceForge.net noreply at sourceforge.net
Sun Nov 19 21:17:41 CET 2006


Bugs item #1599055, was opened at 2006-11-18 19:47
Message generated for change (Comment added) made by montanaro
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1599055&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Closed
Resolution: Wont Fix
Priority: 5
Private: No
Submitted By: Stephen Day (shday)
Assigned to: Nobody/Anonymous (nobody)
Summary: csv module does not handle '\x00'

Initial Comment:
The following from an interactive session failed instead of just returning the '\x00':

>>> r = csv.reader(['a,line,with,a,null,\x00,byte'])
>>> r.next()

Traceback (most recent call last):
  File "<pyshell#31>", line 1, in -toplevel-
    r.next()
Error: string with NUL bytes
>>> 

----------------------------------------------------------------------

>Comment By: Skip Montanaro (montanaro)
Date: 2006-11-19 14:17

Message:
Logged In: YES 
user_id=44345
Originator: NO

If the device is transmitting the occasional spurious you might try
wrapping
your file object in  a class which simply deletes any NUL bytes it
encounters.


----------------------------------------------------------------------

Comment By: Georg Brandl (gbrandl)
Date: 2006-11-19 11:23

Message:
Logged In: YES 
user_id=849994
Originator: NO

The core of the csv module is coded in C, so null bytes are as always
notoriously problematic when handling strings.
(This is why there's a specific error message only for null bytes.)

I think that the try-except is the sanest solution to this.

----------------------------------------------------------------------

Comment By: Stephen Day (shday)
Date: 2006-11-19 11:08

Message:
Logged In: YES 
user_id=948502
Originator: YES

I've been using the csv module to parse data coming from a serial port of
a lab instrument. Occasionally the instrument transmits a lone /x00 (maybe
when the power cycles, I'm not sure).  Anyhow, I'm now using a try-except
statement to catch the error.

I guess my answer to your question is that I think the module should
handle whatever string you pass it. Is there a specific reason not to
handle /x00?


----------------------------------------------------------------------

Comment By: Georg Brandl (gbrandl)
Date: 2006-11-19 09:09

Message:
Logged In: YES 
user_id=849994
Originator: NO

Why do you think a CSV reader should support null bytes?
CSV is a text format, not a binary one.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1599055&group_id=5470


More information about the Python-bugs-list mailing list