LavrykN / py-clean-up-file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Context Manager

Please note: read the guideline before starting.

Create a custom context manager:

In this task, create a custom context manager. Implement the CleanUpFile context manager as a class. It should remove the file if it exists after exiting.

Its constructor should accept only the filename parameter. Also, CleanUpFile must have enter and exit methods.

For example:

with CleanUpFile(“file.txt”):
    with open(“file.txt”, “w”) as file:
        file.write(“Hello Mate!”)

After executing the code, the "file.txt" file should not exist.

About


Languages

Language:Python 100.0%