Help with case cloesd


Trying to test if file is closed and to close it if not but keep getting
"Traceback (most recent call last):
File "python", line 5, in
TypeError: 'bool' object is not callable"
and "Oops, try again. You don't need any parentheses after 'closed'—just my_file.closed should do the trick."
But when I remove the paentheses I get
"Oops, try again. Did you call my_file.close() in the event that my_file.closed returns False?"

Any ideas?

with open("text.txt", "w") as my_file:
    if not my_file.closed:
    print my_file.closed


print my_file.closed

This line should be,
if my_file is not my_file.closed:
and not,
if not my_file.closed:

And here,

You close the file with the syntax, my_file.close not my_file.closed.

And that print statement at the end should only include


Thank you turned out I just needed to change closed() to close()


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.