For those with issues in the File I/O section


#1

I also had an issue where the viewer on the right side of the screen did not accept my code on these lessons.

Since there are many threads asking about this on various lessons, but no threads with a proposed solution in the title, here is one:

It appears you can not create a new file for reading. The current lessons ask you to open in "r+" (read + write) mode, but that throws an error. To work around that, you must initialize your file, similar to variable initialization in other languages.

To do this, insert a line above your "r+" open where you open the file in "w" (write) mode.

One user suggested a rather complicated (though effective) if/then statement to check if the file exists, and if not, create one by opening it in write mode and adding some text. Another workaround is to click the 'output.txt' tab in the editor and add some text, but that will likely only work in this case, making it effective to move through the lessons but not to actually code later on.

Finally, it seems that this issue persists because codecademy is working on a new Python module, so is not fixing it.

Hope this helps. I'm not including my code because it's pretty simple, and we are here to learn!


#2

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