parsing text from "ethtool" command

extraspecialbitter pauldavidmena at gmail.com
Wed Nov 2 08:44:40 EDT 2011


On Nov 1, 7:35 pm, Ian Kelly <ian.g.ke... at gmail.com> wrote:
> On Tue, Nov 1, 2011 at 5:19 PM, Miki Tebeka <miki.teb... at gmail.com> wrote:
> > In my box, there are some spaces (tabs?) before "Speed". IMO re.search("Speed", line) will be a more robust.
>
> Or simply:
>
> if "Speed" in line:
>
> There is no need for a regular expression here.  This would also work
> and be a bit more discriminating:
>
> if line.strip().startswith("Speed")
>
> BTW, to the OP, note that your condition (line[0:6] == "Speed") cannot
> match, since line[0:6] is a 6-character slice, while "Speed" is a
> 5-character string.
>
> Cheers,
> Ian

Ian,

Replacing my regular expression with line.strip().startswith did the
trick.  Thanks for the tip!

Paul



More information about the Python-list mailing list