Posts

Showing posts with the label binaryfiles

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

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? ...