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.

l g,vnZR55roCc
vrEabvQdx2YvfFZQ SLm17h3Al6Uwgv3eE9uaxap46bCG99

Popular posts from this blog

Rothschild family

Boo (programming language)