Nov-17-2017, 07:15 PM
iFunKtion and metulburr,
Thanks for the explanations. Indeed, I have changed to code to use a WHILE loop. Here is the new code:
So now I can mark this thread as "Answered" but I don't see that option. Thanks SO much, folks, for clarifying a confusing basic issue!
Thanks for the explanations. Indeed, I have changed to code to use a WHILE loop. Here is the new code:
1 #!/usr/bin/python 2 # files1.py - first program to play with files 3 # 4 filename = "justsome.txt" 5 6 inp = open(filename, "r") 7 lc = 0 8 9 one_line = "Anything, just not null :-)" 10 #for one_line in inp.readline() : 11 while one_line : 12 one_line = inp.readline() 13 one_line = one_line.rstrip('\n') 14 ll = len(one_line) 15 if ll < 1 : 16 break 17 lc += 1 # Not null: Bump up lines-read count 18 print "Input line[%d] is %d chars: %s" % (lc, ll, one_line) 19 20 # Done printing... 21 # 22 inp.closeAnd voila! the output matches exactly what the readlines() version produced. Actually, slightly better, since the new version skips the final blank line that I got from readlines().
So now I can mark this thread as "Answered" but I don't see that option. Thanks SO much, folks, for clarifying a confusing basic issue!