How to find line number of cursor in Python?

Solution 1:

You can go line-by-line with fileinput:

import fileinput
for line in fileinput.input(encoding="utf-8"):
   process(line)

Solution 2:

Something like enumerate? There's is not really a "cursor" per say but the following will give you the current line number while reading a file line-by-line.

for i, line in enumerate(file):
    print i, line