Bug!: 6. PSA: Buffering Data in the unit File Input/Output

Continuing the discussion from Bug!: 6. PSA: Buffering Data in the unit File Input/Output:

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/en/courses/python-intermediate-en-OGNHh/1/2?curriculum_id=4f89dab3d788890003000096
<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Traceback (most recent call last):
File “python”, line 2, in
IOError: [Errno 2] No such file or directory: ‘text.txt’

```

Open the file for reading

read_file = open(“text.txt”, “r”)

Use a second file handler to open the file for writing

write_file = open(“text.txt”, “w”)

Write to the file

write_file.write(“Not closing files is VERY BAD.”)

write_file.close()

Try to read from the file

print read_file.read()
read_file.close()

<do not remove the three backticks above>

Hi Mark,

Thanks for letting us know about this!

This seems to be a known bug, it’s been around for a while. Unfortunately, it looks like Codecademy doesn’t plan on fixing this any time soon. For now, you can try one of these workarounds from @albionsrefuge:

Workaround 1: go to the text.txt tab and make any insignificant change

Workaround 2: add these two lines to the top of the exercise’s code

my_file = open(“text.txt”,“w”)
my_file.close()


> \- via @albionsrefuge
2 Likes