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
Post a Comment