I have an array called 'thelist' and it holds some numbers which I want to output to a file on the same line delimited with commas. I did this using:
thelist = [1,6,5,2,7]
thefile = open('test.txt', 'w')
name = "bob"
for item in thelist:
thefile.write("%s,"%(item))
output:
1,6,5,2,7,
However, I want to be able to write the name and the array on the same line. So it'd look something similar to bob 1,6,5,2,7
I tried to use thefile.write("%s %s,"%(name,item)) but that unfortunately does not work. I tried to search for an answer but I didn't find a solution. Any ideas? Is this even possible?