Suppose you have a simple generator in Python like this :
Update :
def f(self):
customFunction_1(argList_1)
yield
customFunction_2(argList_2)
yield
customFunction_3(argList_3)
yield
...
I call f() in another script like :
h=f()
while True:
try:
h.next()
sleep(2)
except KeyboardInterrupt:
##[TODO] tell the last line in f() that was executed
Is there a way that I can do the [TODO] section above? that is knowing the last line in f() that was executed before keyboardInterrupt occurred ?
You can use enumerate() to count:
(because in your example
yielddoes not yield a value,valuewill of course be None)Or very explicit using a verbose indication: