for loop: weird behavior

ferreirafm ferreirafm at lim12.fm.usp.br
Fri May 4 16:33:39 EDT 2012


Hi there,
I simply can't print anything in the second for-loop bellow:

#########################################
#!/usr/bin/env python                                                                                                                             

import sys

filename = sys.argv[1]
outname = filename.split('.')[0] + '_pdr.dat'
begin = 'Distance distribution'
end = 'Reciprocal'
first = 0
last = 0
with open(filename) as inf:
    for num, line in enumerate(inf, 1):
        #print num, line                                                                                                                          
        if begin in line:
            first = num
        if end in line:
            last = num
    for num, line in enumerate(inf, 1):
        print 'Ok!'
        print num, line
        if num in range(first + 5, last - 1):
            print line
    print first, last
    print range(first + 5, last - 1)
####################################
The output goes here:
http://pastebin.com/egnahct2

Expected: at least the string 'Ok!' from the second for-loop.

What I'm doing wrong?
thanks in advance.
Fred







--
View this message in context: http://python.6.n6.nabble.com/for-loop-weird-behavior-tp4953214.html
Sent from the Python - python-list mailing list archive at Nabble.com.



More information about the Python-list mailing list