2. The open() Function

Here is my code. I don’t really know what the problem is. All help is appreciated!

my_file = open(“output.txt”, “r+”)

your code is correct , try to write something on output file and save it !!

1 Like

I have that code written as well but I keep getting an error prompt that tells me to create a variable for “my_file”. Is anybody else experiencing this?

Yep :confused: I can not seem to get it either.

I got the same problem with you. And my code just look the same as yours, but i have passed it.
What i did is to copy the code from last lesson “File Input/Output”:f = open(“output.txt”, “w”) and change f to my_file and “w” to “r+”, then passed.
I think there might be something wrong with the format of punctuation mark or something…

1 Like

Thank you for this one :slight_smile:

you can also go to the tab output.txt and just write something in there.
then it will succeed.


Reload the page, go back to 1. See It to Believe It, and click Save & Submit code. Then hit Save & Submit code on 2. The open() Function and it should work.

It seems like you need to remind codecademy that the output.txt file exists.


This works, thanks a lot!