PEP 3107 and stronger typing (note: probably a newbie question)
len-l at telus.net
Sat Jul 14 23:11:00 CEST 2007
Hendrik van Rooyen wrote:
> "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
>> 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:
> print line_number, line
> - Hendrik
I am not defending Pascal or similar languages. Pascal was an
educational language designed to teach structured programming by
removing temptation. The same example in Pascal would be less
convoluted, thought, since Pascal has an explicit end-of-file test
function (No, this is not a Python feature request.) Personally I don't
miss the continuous retesting of conditions made necessary in Pascal.
<len-l at telus.net>
More information about the Python-list