3 ms·
In Python 3 if you have bytes and write them out using the "csv" module, you get something like this: b'A',b'B' b'1',b'2' That's not seamless, and I w
by jzwinck 7y ago
In Python 3 if you have bytes and write them out using the "csv" module, you get something like this:
b'A',b'B'
b'1',b'2'
That's not seamless, and I wouldn't say it helps non-English speakers either.
This bug impacts Pandas to_csv as well.
- deleted 7y ago[deleted]
- agoodthrowaway 7y agoSorry but I don’t agree this is a bug. You need to decode your bytes to properly write a string. Otherwise you get the unexpected result you are showing because it has no way of knowing how your bytes are encoded.
- ASalazarMX 7y agoBut bytes are not strings. Unless you convert them to a string first, they could be an image, a sound, a certificate, etc. Since ASCII strings are always one byte per character, they can be manipulated as bytes, but UTF8 strings aren't. In Python3 you operate with strings and always get strings, you operate with bytes and always get bytes. The string = byte array pattern is an atavism that should not exist this century.