PEP 3107 and stronger typing (note: probably a newbie question)

Hendrik van Rooyen mail at microcorp.co.za
Sat Jul 14 10:03:45 CEST 2007


 "Lenard Lindstrom" <len-l at t...s.net> wrote:


> Pascal has no break, continue or return. Eiffel doesn't even have a 
> goto. In such imperative languages boolean variables are used a lot.

 Thanks did not know this.

> 
> from StringIO import StringIO
> lines = StringIO("one\ntwo\nthree\nfour\n")
> line_number = 0
> eof = False
> found = False
> while not (eof or found):
> line = lines.readline()
> eof = line == ""
> found = line == "three\n"
> if not found:
> line_number += 1
> 
> 
> if found:
> print "Found at", line_number
> else:
> print "Not found"
> # prints "Found at 2"
> 

All right, so it is possible, with some legerdemain,
forcing the main loop to stop when the condition
is met.
However, I find the above as clear as mud, compared to:

line_number = 0

for line in my_file:
  line_number += 1
  if "the Target" in line:
    break

print line_number, line
  
- Hendrik




More information about the Python-list mailing list