Question library
Questions from real interviews. Drill any of them by voice in a couple of minutes, with an interviewer, a score and feedback.
What is a context manager, and how does the with statement work? How do you write your own context manager?JuniorYou need to guarantee that a resource, say a lock or a temporary directory, gets released even if the code inside fails with an exception. How would you implement your own context manager, and how do the different ways of doing it differ?Mid-levelHow does a context manager work under the hood? What happens to an exception inside a with block, and how would you write a manager that handles a database transaction?Senior