Thursday, January 17, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...