Why is this not writing to my data.csv file?
import csv
x = raw_input("Enter FON numbers (seperated by a space)")
integers = [int(i) for i in x.split()]
with open("data.csv", "wb") as f:
writer = csv.writer(f)
writer.writerows(integers)
Why is this not writing to my data.csv file?
import csv
x = raw_input("Enter FON numbers (seperated by a space)")
integers = [int(i) for i in x.split()]
with open("data.csv", "wb") as f:
writer = csv.writer(f)
writer.writerows(integers)
import csv
with open('myCsvFile.csv', 'w') as file:
writer = csv.writer(file)
for i in myList:
writer.writerow(i)
Try something like this. It should work for your purpose.
The function writerows expects instead of int numbers, iterables. Try the following:
import csv
x = input("Enter FON numbers (seperated by a space)")
integers = [[int(i)] for i in x.split()]
with open("data.csv", "w") as f:
writer = csv.writer(f)
writer.writerows(integers)
In case you want to open the file in binary mode, you need to encode your data (otherwise you will receive a TypeError: a bytes-like object is required, not 'str'; you will need to handle the encoding to bytes, as shown here.