[Tutor] Fw: Hi Alan Morne here
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Mon, 2 Sep 2002 15:31:21 -0700 (PDT)
On Mon, 2 Sep 2002, Morne wrote:
> The lines in the file that you will use look like this:
>
> Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: myaddr 155.239.150.146
> hisaddr = 155.239.150.254
> Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: Connect time: 197 secs:
> 5091 octets in, 1864 octets out
> Jul 6 06:30:44 maxigate ppp[34607]: tun0: Warning: Chat script failed
>
>
> if string.find("IPCP",line) > 0:
> connectline = split(line)
> connect.count = connect.count + 1
>
> elif string.find("ERROR",line) > 0:
> error.count = error.count + 1
>
> elif string.find("connect time",line) > 0:
Hi Morne,
One note: if you're looking to see if yolur string contains a certain
substring, be aware that string.find() can also return '0' if it finds
that string at the very beginning. For example:
###
>>> 'hello world'.find('hello')
0
###
So zero is also a perfectly good value as far as find() is concerned.
It's that '-1' value that you want to watch out for:
###
>>> 'hello world'.find('goodbye')
-1
###
Hope this helps!