Excellent! You’re a pro.

Finally, we want to know how to read from our output.txt file. As you might expect, we do this with the read() function, like so:

print my_file.read()



Declare a variable, my_file, and set it equal to the file object returned by calling open() with both "output.txt" and "r".

Next, print the result of using .read() on my_file, like the example above.

Make sure to .close() your file when you’re done with it! All kinds of doom will happen if you don’t.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?