Case Closed?


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:
if my_file.closed == False:
print my_file.closed


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


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.


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