I'm trying to write a list of data bytes to a CSV file. Since it's a list of byte strings, I used the below code:
with open(r"E:\Avinash\Python\extracting-drug-data\out.csv", "wb") as w:
writer = csv.writer(w)
writer.writerows(bytes(datas, 'UTF-8'))
But it results in the following error:
TypeError: encoding or errors without a string argument
datas is a list of byte strings.
print(datas)
yields
[b'DB08873', b' MOLSDFPDBSMILESInChIView Structure \xc3\x97Structure for DB08873 (Boceprevir) Close', b'394730-60-0', b'LHHCSNFAOIFYRV-DOVBMPENSA-N', b'Organic acids and derivatives ', b'Food increases exposure of boceprevir by up to 65% relative to fasting state. However, type of food and time of meal does not affect bioavailability of boceprevir and thus can be taken without regards to food. \r\nTmax = 2 hours;\r\nTime to steady state, three times a day dosing = 1 day;\r\nCmax]
I want the above list to be printed as first row in a CSV file with the decoding of Unicode chars. That is, \xc3\x97 should be converted to it's corresponding character.
str(datas, 'UTF-8')instead? (Also, shouldn't you apply it to each of the elements, instead of the entire list?)writerows, shouldn'tdatasbe a list of lists?TypeError: coercing to str: need a bytes-like object, list founddatasyou are using and how exactly that is supposed to look in the CSV? (There is a'missing indatas, so this seems to be cropped.) Also, how are the\nsupposed to be rendered in CSV, and is this supposed to be a single row, or multiple rows?