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: enter image description here

what should this:
enter image description here

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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -