Yes. Use itertools.islice
:
from itertools import islice
reader = csv.reader(csvfile)
for row in islice(reader, 7, None):
print row
This islice
takes an iterable, then the following positional arguments work a lot like your typical list-slicing start-stop-step:
>>> x = list(range(14))
>>> x[7:None]
[7, 8, 9, 10, 11, 12, 13]
>>> x[7:]
[7, 8, 9, 10, 11, 12, 13]
>>>
>>> list(islice(x, 7, None))
[7, 8, 9, 10, 11, 12, 13]
However, no negative indexing allowed.
>>> list(islice(x, -1, None))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Indices for islice() must be None or an integer: 0 <= x <= maxint.
>>>
However, it is still very flexible, so, for example, taking every-other row starting at the first (i.e. even-numbered rows):
for row in islice(reader, None, None, 2):
print row
Or every-other row starting at the second row (i.e. odd-numbered rows):
for row in islice(reader, 1, None, 2):
print row