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

More pythonic way to do these three lines: http://stackoverflow.com/questions/2081836/reading-specific-lines-only-python