Python CSV, blank rows -
i'm trying create csv file ping times. below have code ping time , put in csv file. unfortunately format in csv files little messed up.
import subprocess sp import csv ip = "216.52.241.254" status,result = sp.getstatusoutput("ping -n 1 -w 1000 " + ip + ' | grep -o time=[0-9]* | grep -o [0-9]*') open('c:/pingdata/test.csv', 'a') csvfile: #result = int(result) cwriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.quote_minimal) cwriter.writerow(result)
the csv file code printing looks like:
i'm looking solution/reason why there blank rows being printed, , why there spaces between numbers (i've tried passing them in integers no avail)
writerow
expects list, takes string list of characters. put in brackets treat list of single string:
cwriter.writerow([result])
Comments
Post a Comment