New submission from Sidhant Bansal <sidhban...@gmail.com>:

The following code
```
import csv
with open("abc.csv", "w") as f:
   data = [b'\xc2a9', b'\xc2a9']
   w = csv.writer(f)
   w.writerow(data)
```
writes "b'\xc2a9',b'\xc2a9'" in "abc.csv", i.e the b-prefixed byte string 
instead of the actual bytes. 

Although one can argue that the write is done in text mode and not binary mode, 
however I believe the more natural expectation by the user will be to have the 
bytes written actually in the "abc.csv".

Can refer to this https://github.com/pandas-dev/pandas/issues/9712 to see one 
of the issues this brings in Pandas. From the discussion on this issue, the 
main reasons of changing this behaviour in Python would be to avoid leaking 
python's encoding system syntax into a generic data exchange format, i.e CSV.

----------
components: Library (Lib)
messages: 369848
nosy: sidhant
priority: normal
severity: normal
status: open
title: Writing bytes using CSV module results in b prefixed strings
type: behavior
versions: Python 3.10

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40762>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to