You use a custom context manager for the with statement to open a file. You run the code, but the file is still open. What can solve it?class customContext: def __init__(myfile,name): myfile.name=name def __enter__(myfile): myfile.file=open(myfile.name, 'r') return myfile.file def __exit__(myfile): if myfile.file:

🎲 Try a Random Question  |  Total Questions in Quiz: 18  |  🧠 Study this quiz with Flashcards
This question is part of a full practice quiz:
Python Core Quiz — practice the complete quiz, review flashcards, or try a random question.

For Pluralsight Skill Assessments.


You use a custom context manager for the with statement to open a file. You run the code, but the file is still open. What can solve it?<br>class customContext:<br> def __init__(myfile,name):<br> myfile.name=name<br> def __enter__(myfile):<br> myfile.file=open(myfile.name, 'r')<br> return myfile.file<br> def __exit__(myfile):<br> if myfile.file: