9.case closed?
below your with … as code,do two things:
1.check if the file is not .closed
2.if that's the case,call .close() on it
3.(you don't need an else here,since your if statement should do nothing if .closed is True)
4.after your if statement,print out the value of my_file.closed to make sure your file is really closed.
with open("text.txt","w") as my_file:
my_file.write("Success!")
if my_file != my_file.closed:
my_file.close()
print my_file.closed