0

Hey Daniweb,

I'm starting out learning python and have been looking around and saw the thread on printing a line that starts with a specific word, I would like to create something similar except take numbers out of text and print them so I can graph them. So far I've written some calculators and a program that links to other programs through a menu.

The Other Thread about Stripping Data

Example: 64 bytes from 74.125.45.106: icmp_seq=0 ttl=46 time=736.635 ms
(74.125.45.106 is Google if anyone is curious.)

I want to take this string and strip it of everything except 736.635. This is only something to try to learn more about Python and improve my skills, I'm happy to read any resources anyone might have. The Idea behind this is so i can plot my Ping time using a spreadsheet graph because it varies so much and I'm curious as to how it changes from hour to hour time however, isn't important for now.

Would anyone happen to have any resources, links, code examples or something I can look at to get an idea of how to start this project? (I did a search on the forum as well)

Thanks for your time and I look forward to hearing your response.

Respectfully,
BombShock

Edited by Bombshock: n/a

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by pyTony
0

You can try the 're' module.

line = "64 bytes from 74.125.45.106: icmp_seq=0 ttl=46 time=736.635 ms"
mobj = re.search(r'^(\d+) bytes from ([0-9.]+): icmp_seq=(\d+) ttl=(\d+) time= ([0-9.]+) ms', line):
print mobj.groups()  # returns ('64', '74.125.45.106', '0', '46', '736.635')
0

if line ends with ms, rpartion, partitition, float.
This sequence of functions with correct arguments should work.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.