Thursday, 17 January 2019

python - Best way to use split and strip

My function scrapes my servers for the command and outputs something along the lines of offset=1.3682 which metrics_emit uses to send to our metrics collector/visualizer, datadog.




What I need to do is strip off the offset= part because metrics_emit only wants the numerical value. What would be the best way of stripping offset= as well as calling strip() on i so that it gets rid of all newlines and trailing/leading whitespaces?



def check(self):
output = sh.ntpq("-nc rv")
out_list = output.split(",")
for i in out_list:
if "offset" in i:
self.metrics_emit('ntp.offset', i)
break

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...