Feb-13-2017, 12:54 PM
(Feb-13-2017, 12:07 PM)BruderKellermeister Wrote: when trying to run your code from above I get:
csvwriter.writerow([line[0], line[columnumber]])
TypeError: a bytes-like object is required, not 'str'
That's strange. For me, the code runs without this error. I'm not sure whether that's relevant in this case, but I am using python in the version 2.7. If you have version 3, that can cause incompatibilities.
And I have to confess that I don't understand this message... the expression in the brackets should be a list, not a string. But 'a bytes-like object', I'm not sure what is included in that and what isn't.
Maybe somone else can help there?
According to the code: you may try to replace the old 'firstlinedone'-part with:
for columnumber, column in enumerate(line): newfilename = "test" + str(column) + "a.csv" if newfilename in listoffilenames: newfilename = "test" + str(column) + "b.csv" listoffilenames.append(newfilename) else: listoffilenames.append(newfilename) newfile = open(newfilename, 'wb') listoffiles.append(newfile) firstlinedone = True
Quote:Any ideas on how to approach getting better at this?Not really, except maybe: try to get stuff done that you need for something else. It keeps up motivation . But learning programming remains hard and difficult for a long time. Don't give up too easily!