Case Closed?


#1



https://www.codecademy.com/en/courses/python-intermediate-en-OGNHh/1/5?curriculum_id=4f89dab3d788890003000096#


My code is working as expected, but I'm not sure why. As far as I can tell, "my_file" hasn't been defined anywhere, so I don't know why it is working when I call it. My best guess is that each exercise is using the previous exercise's code and storing it in the background somehow; is this the case? If not why is my_file working.


with open("text.txt","w") as textfile:
    textfile.write("blablablabla")
if my_file.closed == False:
    my_file.close()
print my_file.closed


#2

Seems like it'd be the case... In terms of Python, it shouldn't work.


#3

For some of the instructional material, such as the Python track, Codecademy maintains a cache of objects in memory while you are working on an exercise. This may include objects from previous exercises in the same course. Therefore in some cases, code that is incomplete may pass. To remove obsolete objects from Codecademy's memory cache, refresh the page.

In the current case, you can make your code correct by either replacing all occurrences of my_file with textfile or by replacing all occurrences of textfile with my_file.

Congratulations, @1dec0, on completing the final Python exercise.


#4

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