Unable to open file for reading

I’m a beginner in Python and following some examples in a tutorial.

A filename “myText.txt” was created but couldn’t be read:

f = open(“myText.txt”, “w”)
print (f.read())

Error message is:
Traceback (most recent call last):
File “”, line 1, in
io.UnssupportedOperation: not readable

This was followed exactly from an online tutorial but wasn’t able to execute on my comp.

“w” opens file for writing only, and creates if it doesn’t exist.

If you want to read and write the file, use “w+”

You opened the file for writing (with ”w”) but you’re trying to read from it. Just use f = open(“myText.txt”), since reading is the default mode.

For further explanation, using open("myText.txt") is equivalent to open("myText.txt, "r") since "r" (read-only mode) is the default option for the second positional parameter of open(). I figured it might be worth mentioning since the behavior of defaults are not always obvious to new users of the language.