I need something like this:
from contextlib import contextmanager @contextmanager def loop(seq): for i in seq: try: do_setup(i) yield
But the contextmanager does not work, because it expects the generator to give exactly once.
The reason I want this is because I basically want to make my own for the loop. I have a modified IPython that is used to control test equipment. This is obviously a complete Python REPL, but most of the time the user simply calls the predefined functions (similar to the Bash prompt) and the user does not have to be a programmer or familiar with Python. There should be a way to iterate over some arbitrary code with setting / clearing and handling exceptions for each iteration, and it should be about as easy to type as indicated above using the instructions.
source share