From: V N on 1 Jul 2010 13:10 string "\x00" has a length of 1. When I use the csv module to write that to a file csv_f = csv.writer(file("test.csv","wb"),delimiter="|") csv_f.writerow(["\x00","zz"]) The output file looks like this: |zz Is it possible to force the writer to write that string?
From: anon on 1 Jul 2010 15:13 V N wrote: > string "\x00" has a length of 1. When I use the csv module to write > that to a file > > csv_f = csv.writer(file("test.csv","wb"),delimiter="|") > csv_f.writerow(["\x00","zz"]) > > The output file looks like this: > |zz > > Is it possible to force the writer to write that string? This will do what you want: "\\x00"
From: MRAB on 1 Jul 2010 16:04 V N wrote: > string "\x00" has a length of 1. When I use the csv module to write > that to a file > > csv_f = csv.writer(file("test.csv","wb"),delimiter="|") > csv_f.writerow(["\x00","zz"]) > > The output file looks like this: > |zz > > Is it possible to force the writer to write that string? It can write "\x01" but not "\x00", and "\x00ABC" doesn't write anything either. The csv module imports from _csv, which suggests to me that there's code written in C which thinks that the "\x00" is a NUL terminator, so it's a bug, although it's very unusual to want to write characters like "\x00" to a CSV file, and I wouldn't be surprised if this is the first time it's been noticed! :-)
From: John Machin on 2 Jul 2010 08:12 On Jul 2, 6:04 am, MRAB <pyt...(a)mrabarnett.plus.com> wrote: > The csv module imports from _csv, which suggests to me that there's code > written in C which thinks that the "\x00" is a NUL terminator, so it's a > bug, although it's very unusual to want to write characters like "\x00" > to a CSV file, and I wouldn't be surprised if this is the first time > it's been noticed! :-) Don't be surprised, read the documentation (http://docs.python.org/ library/csv.html#module-csv): """Note This version of the csv module doesnt support Unicode input. Also, there are currently some issues regarding ASCII NUL characters. Accordingly, all input should be UTF-8 or printable ASCII to be safe; see the examples in section Examples. These restrictions will be removed in the future.""" The NUL/printable part of the note has been there since the module was introduced in Python 2.3.0.
|
Pages: 1 Prev: Solutions for hand injury from computer use Next: Python 2.4.2 Installation error |