fixes #4277 this time in pure python (no calls to bash)

And if you want to get fancy, I like context managers to make sure files get closed, so you would do something like this:

with open(filename) as fp:
    for i, line in enumerate(fp):
        blah