tags:

views:

52

answers:

1

hi,

please excuse me for simple question: i tried to write simple csv file using csv module. however, the result is this:

Spam |Baked Beans|
/ s e a r c h | | , | | A d v a n c e d | | S e a r c h
/ a b o u t / | | , | | A b o u t
/ n e w s / | | , | | N e w s
/ d o c / | | , | | D o c u m e n t a t i o n
/ d o w n l o a d / | | , | | D o w n l o a d
/ c o m m u n i t y / | | , | | C o m m u n i t y
/ p s f / | | , | | F o u n d a t i o n
/ d e v / | | , | | C o r e | | D e v e l o p m e n t
/ a b o u t / h e l p / | | , | | H e l p

the code i use is:

spamWriter = csv.writer(open('links.csv', 'w'), delimiter=' ',quotechar='|', quoting=csv.QUOTE_MINIMAL)
spamWriter.writerow(['Spam']  + ['Baked Beans'])
spamWriter.writerow(self.linkvalue + ' , '  + data)

linkvalue and data are two variables that hold some data.

thank you for your advice!!!!

+6  A: 

writerow's argument is a sequence... and a string, which is what you're passing, is a sequence of single characters. To fix your bug, in the 2nd call to writerow, pass, instead, [self.linkvalue, data] as the argument.

Alex Martelli
simple, elegant answer! Thank you!!!
john
@john, you're welcome!
Alex Martelli
hope you don't mind i put your name in our community site:http://www.newsino.org/node/80
john
@john, sure, no problem!
Alex Martelli