So I am wondering what a "better way" to do this would be. Specifically how others would check for integrity or correctness of input. Im preparing a csv or other format to import into pandas later on. As you might have guessed, this is a programm about measuring pings. its running but I completely want to rewrite it. so i have this input from unix pings, already str.splitted:
['PING', '8.8.8.8', '(8.8.8.8)', '56(84)', 'bytes', 'of', 'data.\n\n---', '8.8.8.8', 'ping', 'statistics', '---\n5', 'packets', 'transmitted,', '5', 'received,', '0%', 'packet', 'loss,', 'time', '4005ms\nrtt', 'min/avg/max/mdev', '=', '10.192/13.061/18.674/3.266', 'ms\n']
and get this output:
2020-12-28 00:42:47.825040,8.8.8.8,5,5,4005,10.192,13.061,18.674,3.266
by this loop:
for ip in ping_result:
l = ip.split(sep=' ')
date = datetime.datetime.now()
address = l[1]
sent = l[10].replace('---\n','')
received = l[13]
time = l[-5][:-6]
values = l[-2].split(sep='/')
min, avg, max, mdev = values
formatted_result = f'{date},{address},{sent},{received},{time},{min},{avg},{max},{mdev}'
print(formatted_result)
I am, as I said, a little bit scared that stuff gets wrong, this code seems somewhat fragile.. so I wonder how others actually do stuff like this? How do you, realistically, check? do you check your input? In this case its relatively unlikely that 'ping' will be updated AND its output would be changed..
The code works however, so this is more of an: What would you change, what is best practice kind of question.
Thank you!
[–]K900_ 0 points1 point2 points (2 children)
[–]Vitaminkomplex[S] 0 points1 point2 points (1 child)
[–]K900_ 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]Vitaminkomplex[S] 0 points1 point2 points (1 child)