Write data to one csv row Python -


in py script, need write data csv file result of 5 columns per row.

title:info title title title title      1        2  3 4  5  1        2  3 4  5 title:info title title title title   1        2  3 4  5 

i want use file.write() method, not csv module if @ possible.

for ip in open("list.txt"):     open("data.txt", "a") csv_file:         csv_file.write("\r title:" + ip + ", title, title, title, title \r")         line in open("0820-org-apflog.txt"):             new_line = line.split()             #search apflog correct lines             if "blocked" in new_line:                 if "src="+ip.strip() in new_line:                     #write columns new text file & remove headers lines in files , add commas                     csv_file.write(ip + ", " + new_line[11].replace("dst=", ", ") + new_line[12].replace("proto=", ", "))                     try:                         csv_file.write(new_line[14].replace("dpt=", ", "))                     except indexerror:                         pass 

when run script, result:

title:info           title title title title 1           2 3 4 5 

i have tried: csv_file.write('%r\n%r\n%r\n' % (one, three, four)) , variations, data isn't working way need to.

i don't know code wrong. thought .write() write data same row unless otherwise specified (from previous uses).

question: how .write() 1 line of pattern 1 csv row, , still separate pattern different rows?

thanks!

strip trailing newline line read first.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -