|
I've a Python script (originally 2.xx) now running in 3.xx and I think the way Python 3 uses Unicode is causing problems - but let me keep it simple. Using Python 3, there is a strict division between text (str) and data (bytes) and text can't be written to a file if it isn't explicitly encoded first. The below code works fine so long as using the print function to the screen - it's collected data from a Microsoft SQL database by the by. BUT - it wont write out to a csv file which is what I really want it to do. I'd be very grateful for any pointers and I am a total Python newbie!!! I have tried specifying utf8 via various methods and at various points but it never seems happy? Current error with the below is :- TypeError: 'str' does not support the buffer interface - So how do we make CSVRow compatible with the csv writer is my issue :-> The code: c=csv.writer(open('D:pythonscriptsoutput.csv', 'wb')) for row in Result: CSVRow=((row[0]),(row[1]),(row[2]),(row[3]),(row[4]), (row[5]), (row[6]), (row[7]), (row[8]), (row[9]), (row[10]), (row[11]), (row[12]), (row[13]), (row[14]), (row[15]), (row[16]), (row[17]), (row[18]), (row[19]), (row[20]), (row[21]), (row[22]), (row[23]), (row[24]), (row[25]), (row[26]), (row[27]), (row[28]), (row[29])) c.writerow([CSVRow]) print (CSVRow) c.close() |
what this has to do with splunk?? splunk uses python 2.7.2