Refine your search:

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()

asked 23 Feb '12, 08:18

TheMarkHodgkinson's gravatar image

TheMarkHodgk...
203
accept rate: 0%

closed 23 Feb '12, 08:23

araitz's gravatar image

araitz ♦
7.9k3925

what this has to do with splunk?? splunk uses python 2.7.2

(23 Feb '12, 08:22) MarioM

The question has been closed for the following reason "Please repost to stackoverflow or a Python development forum." by araitz 23 Feb '12, 08:23

Follow this question

Log In to enable email subscriptions

RSS:

Answers

Answers + Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×510
×181
×155
×14
×1

Asked: 23 Feb '12, 08:18

Seen: 783 times

Last updated: 23 Feb '12, 08:23

Copyright © 2005-2012 Splunk Inc. All rights reserved.