From the research I've been doing, this code should write text into a CSV file.
import csv
name = "X"
score = "Y"
with open('some.csv', 'wb') as f:
writer = csv.writer(f)
data = [["Name", "Score"],
[name,score]]
f.write(data[0].encode('utf-8'))
writer.writerows(data)
At first, it threw me an encoding error. After hunting around on Stack Overflow, I found something about needing to encode the text into UTF8. So I tried encoding with X.encode(). Then I got this:
f.write(data[0].encode('utf-8'))
AttributeError: 'list' object has no attribute 'encode'
I can't find an answer as to why this is happening. Can anyone explain why I'm getting this error?
data[0]is["Name", "Score"]not a string.