Python - Remove Braces and Commas from a Tuple CSV File -


i'm printing out csv file this:

bdictionary = ## bdictionary big list of tuples w = csv.writer(open("testnucsv.csv", "w")) sent in bdictionary:     w.writerow(sent) 

and prints out fine , looks this:

(u'my', u'd') (u'dog', u'n')............... (u'the', u'd') ............................

how can print out this

my d dog n d

this tried, , isn't working. splits every charachter:

w = csv.writer(open("testnucsv.csv", "w")) sent in bdictionary:     sent = ''.join(str(v) v in sent)     w.writerow(sent) 

wrap in list, writerow expects iterable iterates on string splitting single characters:

sent = [' '.join(" ".join(v) v in sent)] 

you need join strings in tuple above not call str on tuple i.e:

t = [(u'my', u'd'), (u'dog', u'n')]  print(" ".join([" ".join(v) v in t])) d dog n 

you use file.write , pass joined string:

with open("testnucsv.csv", "w") f:    sent in bdictionary:         f.write(" ".join([" ".join(v) v in sent])+"\n") 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -