As a basic example, imagine the following:
with runFiveTimes:
print("test")
Is this possible in Python?
(This example is only to clarify the question, obviously there are much easier ways of achieving this specific example)
As a basic example, imagine the following:
with runFiveTimes:
print("test")
Is this possible in Python?
(This example is only to clarify the question, obviously there are much easier ways of achieving this specific example)
It's not possible. I tried to add multiple yield statements to a context manager, and Python threw a fit. This answer addresses that more, and explains some good alternatives.
This guy examined the bytecode produced, and found that this is not possible. (This guide explains what each bytecode means.)
And this guy shows that the context manager is stored on the heap, which is where classes go, not objects.