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

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')

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.