How to implement somethig like the 'head' and 'tail' commands in python and backward read by lines of a text file?