So I am implementing a pathfinding algorithm in python and I want to look how each iteration looks like. So I made it a generator that will yield every intermediate result up until the final result which will end with a return
statement.
I made a quick pygame (because I am not aware of python libraries yet, so it was the simplest for me to make a grid and color the cells) program to visualize everything. Every frame makes an iteration on the algorithm and updates a variable result = next(alg)
. The problem is when the algorithm ends, It still tries to go next. I was wondering if there is a way around this other than catching the stopiteration error. The best for me would be something like if not alg.over() : result = next(alg)
, but I found nothing on the internet. Is there something like that that I can use? Thank you !