| 1 | How would you implement asynchronous file I/O using aiofiles alongside an async context manager, to avoid blocking the event loop during file operations? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Advanced |
| 2 | How do you implement contextlib.ExitStack to dynamically manage a VARIABLE number of context managers determined at runtime? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Advanced |
| 3 | How do you use multiple context managers in a single 'with' statement, and how does this compare to nesting separate 'with' blocks? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Intermediate |
| 4 | How would you write a context manager that atomically writes to a file, avoiding leaving a corrupted or partially-written file if an exception occurs mid-write? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Advanced |
| 5 | How do you open and read a text file using the 'with' statement, and why is 'with' preferred over manual open()/close()? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Beginner |
| 6 | What is the difference between reading a file with .read(), .readline(), and .readlines()? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Beginner |
| 7 | What are the common file modes ('r', 'w', 'a', 'rb') passed to open(), and what does each one do? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Beginner |
| 8 | How do you write and use a custom context manager by implementing __enter__ and __exit__? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Intermediate |
| 9 | How does @contextlib.contextmanager let you write a context manager using a generator function instead of a full class? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Intermediate |
| 10 | How do you use pathlib.Path for modern, object-oriented file path manipulation instead of os.path's string-based functions? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Intermediate |
| 11 | How do you check whether a file or directory exists before operating on it, using pathlib? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Intermediate |
| 12 | How would you implement a context manager that temporarily changes the current working directory and restores it afterward? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Advanced |
| 13 | How would you write a reusable context manager decorator using contextlib.contextmanager that ALSO works when applied directly to a function, like @contextmanager-decorated functions support? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Advanced |
| 14 | How would you implement a context manager for managing a lock (like threading.Lock) while ALSO adding a timeout, raising an error if the lock can't be acquired quickly enough? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Advanced |
| 15 | How do you correctly handle character encoding when reading text files that might not be UTF-8, and what error occurs if you guess wrong? Python › File I/O & Context Managers | Python | File I/O & Context Managers | Advanced |
| 16 | How do context managers and the `del` statement relate to timely memory cleanup versus relying on garbage collection? Python › Memory Management & Garbage Collection | Python | Memory Management & Garbage Collection | Intermediate |
| 17 | How does context manager __exit__ interact with exception handling, and how can it SUPPRESS an exception by returning True? Python › Exception Handling | Python | Exception Handling | Advanced |
| 18 | How would you write a context manager using @contextlib.contextmanager that both sets up a resource AND properly handles/logs any exception that occurs while it's in use? Python › Exception Handling | Python | Exception Handling | Advanced |
| 19 | How does the iterator protocol interact with the with-statement for resource-managing iterables like file objects? Python › Iterators & the Iterator Protocol | Python | Iterators & the Iterator Protocol | Advanced |
| 20 | How do RotatingFileHandler and TimedRotatingFileHandler prevent log files from growing unbounded? Python › Logging | Python | Logging | Advanced |
| 21 | How do context manager magic methods __enter__ and __exit__ work, and what does __exit__'s return value control? Python › Magic Methods & Operator Overloading | Python | Magic Methods & Operator Overloading | Advanced |
| 22 | What does the 'finally' block guarantee, and when is it typically used? Python › Exception Handling | Python | Exception Handling | Beginner |
| 23 | How do you manually exhaust and inspect an iterator without a for-loop? Python › Iterators & the Iterator Protocol | Python | Iterators & the Iterator Protocol | Beginner |
| 24 | How does Python's iter() function work with a sentinel value as a second argument? Python › Iterators & the Iterator Protocol | Python | Iterators & the Iterator Protocol | Intermediate |
| 25 | How would you write a descriptor supporting attribute DELETION via __delete__, and what real use case does that enable? Python › Descriptors & Properties | Python | Descriptors & Properties | Advanced |
| 26 | Why is logging generally considered thread-safe, and what should you still be careful about in multiprocessing? Python › Logging | Python | Logging | Advanced |
| 27 | Why is __del__ (the finalizer method) discouraged for critical cleanup logic, and what problems can it cause? Python › Memory Management & Garbage Collection | Python | Memory Management & Garbage Collection | Advanced |