bpo-40762: Fix writing bytes in csv#20371
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
35cba89 to
4dc7ebe
Compare
remilapeyre
left a comment
There was a problem hiding this comment.
Hi @sidhant007, thanks for proposing this PR but as noted on bpo the csv module explicitely only deals with strings and numbers and other types must converted first. I don't think guessing the encoding of random bytes can be accepted.
a854fe1 to
21c28fd
Compare
|
Hi @remilapeyre, I have updated the docs in this PR to state that csv should allow writing bytes as well in the text mode. Also this fix is not guessing the encoding, rather it is using the encoding scheme provided in the Also I would suggest we move all this discussion to the bpo issue tracker, to avoid the discussion getting fragmented in two different places. |
21c28fd to
a3de955
Compare
|
Hi @sidhant007, as per the discussion on bpo this option has been rejected in favor of a |


Changes how bytes are written in csv. Changes writing bytes as strings to writing them as bytes.
Ex.
This code currently writes
b'A',b'A'inabc.csv, i.e the b-prefixed string instead of the actual bytes, whereas the natural expectation is for the actual bytes to be written (i.eA,A) inutf-8or whatever encoding is specified inopen.This un-natural behaviour has been covered in this Pandas issue also.
https://bugs.python.org/issue40762