I am reading a file in Python. After I read a bunch of lines, is there a convenient function that I can use to get the current line number in the file that the cursor is on?
I am trying to refrain from using a counter since I have multiple functions that read the same file and may move the cursor all over the place.
Thanks
You can go line-by-line with fileinput:
import fileinput for line in fileinput.input(encoding="utf-8"): process(line)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With