how to use the binary mode for csv file in python 3.6?

Multi tool use
Multi tool use


how to use the binary mode for csv file in python 3.6?



I have the following code :


file_name="data.csv"
temp_file=NamedTemporaryFile(delete=False)

with open(file_name,"rb") as csvfile, temp_file: #b stands for binary
reader=csv.DictReader(csvfile)
fieldnames=['id','name', 'email', 'amount', 'sent']
writer=csv.DictWriter(temp_file, fieldnames=fieldnames)
#writer.writeheader()
print(temp_file.name)
for row in reader:
print(row)
writer.writerow({
"id":row["id"],
"name":row["name"],
"email":row["email"],
"amount":"1293.33",
"sent":""
})



and the following error:
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)



what should be done?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Qmv35Nw,n0OiZDwZTJdC H5lC9b,AgU3avsNEXMNKHd3c,6kgg,o45Qh
tWdBcdWMBSRlvu K,2 v940OotQsRuOrWoNoK EAs3 paxLYhEfGCQwsX,UzwFWv,qJMuOnTF

Popular posts from this blog

Rothschild family

Cinema of Italy