[Tutor] Search text file, perform action if a given item found
eric at digitalert.net
Fri Sep 10 10:31:31 CEST 2004
I'm still new to this so please bare with me. I have spent a few hours
searching google, and trying different combinations
and can't seem to figure out how to use endswith() to search a list, and
to then take a action. In my case I would want to search through
the port number, and from there depending on if it finds a match it
would go through a if-else statement, and then loop back
to he start to continue monitoring. I think I can handle the second
part, but searching a list, and taking a action based on that search is
that I am having a hard time grasping. Any help would be greatly greatly
This is the output of print l.split()[1:2]
>> Next you probably want to split() the line to divide it into fields.
>> Then you can look at the specific fields. You might be able to use
>> endswith() or find() to search for the port; in my example
>> endswith(':25') for example would find the line with port 25. The
>> details depend on what your data looks like.
>> Give this a try and let us know how far you get. Also it would be
>> helpful to see an example of the output of netstat on your computer,
>> it is different on Windows and MacOSX.
More information about the Tutor