class Test:
def __init__(self):
pass
def __enter__(self):
pass
def __exit__(self, exc_type, exc_val, exc_tb):
pass
with Test():
print (1) # any way to ignore it?
Is there a way ignore (not to execute) with
statement body?
That is in this case I don't want print (1)
to be executed (but I don’t want to wrap this expression in a function, etc.)
I need this for one personal experimental project.
Tried some options, like throwing exceptions, but it doesn't seem to work.
PS:
I cannot wrap with
body in any constructions (at least until the Test class is called).
I would like to implement this inside the Test class, for example, when calling a class, some monkeypatch may work and so on.
PS2: the program should still work after ignoring a with body