Rémi Lapeyre <[email protected]> added the comment:
> As an example, if I write character "A" as a byte, i.e b'A' in a csv file
But you can't write b'A' in a csv file, what you can't do is write
`b'a'.decode()` or `b'a'.decode('latin1')` or `b'a'.decode('whatever')` but the
string representation of a byte string is dependant on the character encoding
and it's not possible to guess it, which is why bytes and string were separated
in Python3 in the first place.
Since csv can't write bytes, it gets a string representation of the by calling
str(), as it would with any other objects.
> which is not what the user would have wanted in majority of the use-cases
If you try to guess the encoding, you will obligatory fail in some case and the
resulting file will be corrupted. The only way here is for your users to fix
their program and decode thee byte string using the correct encoding before
giving them to csv.
----------
nosy: +remi.lapeyre
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue40762>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com