How can I check if my file is closed or not?
if statement looks like this:
if some_expression: # Run this code!
The value stored in the file’s
closed attribute will be either
False, so we can directly check it in our
if statement, like this:
However, we want to check if it is not closed, so you’ll need to alter the expression slightly. Then, be sure to indent the code you want inside of your
if statement using 2 spaces.