Skip to content

Instantly share code, notes, and snippets.

@kmerenkov
Created November 21, 2011 14:21
Show Gist options
  • Save kmerenkov/1382742 to your computer and use it in GitHub Desktop.
Save kmerenkov/1382742 to your computer and use it in GitHub Desktop.
$ cat n_line.py
# -*- coding: utf-8 -*-
from itertools import islice
from cStringIO import StringIO
_content = """1st line
2nd line
3rd line
4th line
5th line"""
def nth_line(f, n):
x = list(islice(f, n, n+1))
return x[0] if x else None
f = StringIO(_content)
fourth_line = nth_line(f, 3)
print fourth_line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment