educative.io

Error in context manager suppress lesson

In Context Manager lesson under “Contextlib and Its Classes”, there is an error with the lesson for the suppress class. The first code example is supposed to show how the context manager would not work by throwing an exception to a FileNotFoundError. However, the code runs fine since the filename used exists in the directory so the code runs without errors, which is not aligned with the lesson trying to display an error. To solve this, rather remove the file in the directory, or rename the filename argument in the open method to a file that does not exist.