[Tutor] Dodgey if loop ?

Roger Merchberger zmerch at 30below.com
Tue Sep 7 06:53:48 CEST 2004

Rumor has it that nick at javacat.f2s.com may have mentioned these words:

Others have mentioned a problem with your algorithm, but there is an 
indentation problem with your code:

>Here's the offending code:
>pnumber = str(pnumber) #pnumber is 25 for example
>for line in f: # f is '/etc/services' open file
>     if not line.startswith('#') and len(line) > 10:
>         p = line.split()[1].split('/')[0]
>             if p == pnumber:

This line should not be indented -- and *might* cause problems, tho
I did not test the code...

>                 return line.split()[0] # would return 'smtp'
>             #else:
>                 #return '?'

Hope this helps,
Roger "Merch" Merchberger

Roger "Merch" Merchberger   | A new truth in advertising slogan
sysadmin, Iceberg Computers | for MicroSoft: "We're not the oxy...
zmerch at 30below.com          |                         ...in oxymoron!"

More information about the Tutor mailing list