I've looked at the posts here and here. But they have either been trying to write bytes to a CSV or saving a CSV from a string but I'm trying to connect trying writing bytes to a CSV.
I have a blob of bytes
and if I do type(bytes)
I get <class 'bytes'>
but when I try to write to a csv I get an error
(Pdb) f = open('/Users/minhmai/test.csv', 'wb+')
(Pdb) writer = csv.writer(f)
(Pdb) writer.writerow(bytes)
*** TypeError: a bytes-like object is required, not 'str'
(Pdb) f = open('/Users/minhmai/test.csv', 'wb+')
(Pdb) writer = csv.writer(f)
(Pdb) writer.writerows(bytes)
*** _csv.Error: iterable expected, not int
However If I do this, I just get a number but it's not really saved to a CSV.
(Pdb) wfile = io.StringIO()
(Pdb) writer = csv.writer(wfile)
(Pdb) writer.writerow(bytes)
And example of what my data(bytes
) look like is this
b'Date,ID,Amount\r\n2018-1-1,1,25\r\n2018-1-2,2,3\r\n2018-1-1,2,3\r\n`
Ideally this would result in a header row and 3 rows