timeit("print getline('afile', 4003) + getline('afile', 4004)",
    'from linecache import getline', number=1)
timeit("getline('afile', 4003) + getline('afile', 4004)",
    'from linecache import getline', number=10 ** 5)
timeit("''.join(islice(open('afile'), 4003, 4005))",
    'from itertools import islice', number=10 ** 5)
Python fastest access to line in file