Re: csv and mixed lists of unicode and numbers

2009-11-25 Thread Sibylle Koczian
Terry Reedy schrieb: In Python 3, a file opened in 'b' mode is for reading and writing bytes with no encoding/decoding. I believe cvs works with files in text mode as it returns and expects strings/text for reading and writing. Perhaps the cvs doc should say must not be opened in 'b' mode. Not

Re: csv and mixed lists of unicode and numbers

2009-11-25 Thread M.-A. Lemburg
Sibylle Koczian wrote: > Hello, > > I want to put data from a database into a tab separated text file. This > looks like a typical application for the csv module, but there is a > snag: the rows I get from the database module (kinterbasdb in this case) > contain unicode objects and numbers. And of

Re: csv and mixed lists of unicode and numbers

2009-11-24 Thread Terry Reedy
Sibylle Koczian wrote: Peter Otten schrieb: I'd preprocess the rows as I tend to prefer the simplest approach I can come up with. Example: def recode_rows(rows, source_encoding, target_encoding): def recode(field): if isinstance(field, unicode): return field.encode(targ

Re: csv and mixed lists of unicode and numbers

2009-11-24 Thread Peter Otten
Sibylle Koczian wrote: > This problem really goes away with Python 3 (tried it on another > machine), but something else changes too: in Python 2.6 the > documentation for the csv module explicitly says "If csvfile is a file > object, it must be opened with the ‘b’ flag on platforms where that > m

Re: csv and mixed lists of unicode and numbers

2009-11-24 Thread Sibylle Koczian
Peter Otten schrieb: > I'd preprocess the rows as I tend to prefer the simplest approach I can come > up with. Example: > > def recode_rows(rows, source_encoding, target_encoding): > def recode(field): > if isinstance(field, unicode): > return field.encode(target_encoding)

Re: csv and mixed lists of unicode and numbers

2009-11-24 Thread Peter Otten
Sibylle Koczian wrote: > I want to put data from a database into a tab separated text file. This > looks like a typical application for the csv module, but there is a > snag: the rows I get from the database module (kinterbasdb in this case) > contain unicode objects and numbers. And of course the

Re: csv and mixed lists of unicode and numbers

2009-11-24 Thread Benjamin Kaplan
On Tue, Nov 24, 2009 at 11:42 AM, Sibylle Koczian wrote: > Hello, > > I want to put data from a database into a tab separated text file. This > looks like a typical application for the csv module, but there is a > snag: the rows I get from the database module (kinterbasdb in this case) > contain u

csv and mixed lists of unicode and numbers

2009-11-24 Thread Sibylle Koczian
Hello, I want to put data from a database into a tab separated text file. This looks like a typical application for the csv module, but there is a snag: the rows I get from the database module (kinterbasdb in this case) contain unicode objects and numbers. And of course the unicode objects contai