Case Closed?


#1



Im confused with the last exercise... am i missing something???


with open("text.txt", "w") as my_file:
    my_file.write("Success!")
f = open('my_file')
if f.closed:
    print 'file is not closed'
 elif f.close:
     print 'file is closed'
print my_file.closed


#2

You used closed here which is cool and

close here which isn't right.

Lastly, your indentation.


#3

Thank you :slight_smile: I greatly appreciate the help. I tried doing what you mentioned but still not working :neutral_face:.


#4

Below your with...as segment of code, you want to have a simple if statement that tests the result of my_file.closed
your line "f = open('my_file')" is not necessary here.

In your if statement remember that you need to test the "dot"closed value of my_file


#5

Well, what @andy_orr mentioned is noteworthy.

What the exercise requires of you is to:

with open("text.txt", "w") as my_file: 
    my_file.write("Success!")
    if not my_file.closed: """Check if the file is not .closed"""
        Done = my_file.close()
    print my_file.closed """print out the value of my_file.closed"""

Hope this explains it! :slight_smile:


#6

with open("text.txt", "w") as my_file:
my_file.write("Success!")
if not my_file.closed: """Check if the file is not .closed"""
Done = my_file.close()
print my_file.closed """print out the value of my_file.closed"""
Edit error: "IndentationError: unindent does not match any outer indentation level"


#7

Please copy and paste the below and see. Indentation is fine! :slight_smile:

with open("text.txt", "w") as my_file:
    my_file.write("Success!")
    if not my_file.closed:
        Done = my_file.close()
    print my_file.closed

#8

try the code below. I am sure it will be helpful:

with open("text.txt","w") as my_file:
my_file.write("this is my file")
if not my_file.closed :
my_file.close()
print my_file.closed