Timtam
Timtam

Reputation: 223

python csv is separating too much

here's my code

 f= open('test1.txt','r') 
 todo = open('fb12.txt','w')     
 reader = csv.reader(f,delimiter=' ', quotechar='|')
 writer = csv.writer(todo)     
 for row in reader:
     writer.writerows(row)

I want the output to be just the same as the input it should look like this

"DDD","3D Systems Corporation","23.47","1100203190","n/a","Technology","Computer Software: 
 etc.

instead I got this:

"""",D,D,D,"""",",","""",3,D

S,y,s,t,e,m,s

C,o,r,p,o,r,a,t,i,o,n,"""",",","""",2,3,.,4,7,"""",",","""",1,1,0

S,o,f,t,w,a,r,e,:

P,r,e,p,a,c,k,a,g,e,d

HELP!

Upvotes: 1

Views: 123

Answers (1)

Raymond Hettinger
Raymond Hettinger

Reputation: 226534

You've got one too many layers of iteration :-)

Replace the for-loop with:

writer.writerows(reader)

Or change the writerows to writerow:

for row in reader:
    writer.writerow(row)

Upvotes: 2

Related Questions