Sunday 15 June 2014

python - Issues outputting strings vs lists from CSV -



python - Issues outputting strings vs lists from CSV -

so have below code that's meant take csv file of 4 columns, add together in 1 or 2 pipes (for mediawiki table formatting), , spit them out ready copy/paste usage.

import csv open("example.csv", 'r') csvfile: row in csv.reader(csvfile): row[0] = "|" + str(row[0]) row[1] = "||" + str(row[1]) row[2] = "||" + str(row[2]) row[3] = "||" + str(row[3]) f = open("finished.txt", "a") ', '.join(row) f.write(str(row))

the input looks following:

advertising,mobile phone app,coupon,android

and when refer outputted contents, appears so:

['|advertising', '||mobile phone app', '||coupon', '||android']

now it's quite i've gone goal terribly above code, i'd know how best output without brackets, commas, , apostrophes.

you need right f.write statement. stands, writing string representation of row, happens list, , not bring together of in file. though have done join on string, row remains unaffected.

f.write(', '.join(row))

python csv

No comments:

Post a Comment