Your question is Python Context Managers. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
python里的with怎么实现的
Asked in the coding round 1 stage. Same interviewer, Python internals.
Implement context_manager_trace(should_raise, suppress_exception) using a custom context manager. It must record the order of __enter__, the with-body, and __exit__. If the body raises ValueError, __exit__ decides whether the exception is suppressed. The function must return the trace, including propagated when the exception escapes the with statement.
Input: two booleans. Output: a list of strings.
should_raise and suppress_exception are booleansValueErrordef context_manager_trace(should_raise, suppress_exception):