S
S
Swalton2015-10-28 18:05:28
Python
Swalton, 2015-10-28 18:05:28

Why can't read from file - io.UnsupportedOperation: not readable?

I wrote a simple code in Notepad++ in Python. Launched on this video. Here is the code:
f=open('text.txt','w')
f.write("adc")
f.read()
After running, I got this message:
Traceback (most recent call last):
File "C:\ Users\ZERO\Desktop\Programming\new1.py", line 3, in
f.read()
io.UnsupportedOperation: not readable
So gentlemen, what's the problem?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Roman Kitaev, 2015-10-28
@Swalton

How many accolades.
You yourself opened the file for writing, and then you want to read it. Do not do it this way.

Z
Zelimkhan Beltoev, 2015-10-28
@Beltoev

Is it okay that you opened the file for writing and are trying to read from it? Python says so, read the errors, after all

S
Swalton, 2015-10-28
@Swalton

Clearly, thanks, I just met Python`om yesterday. So, sorry for the stupid question.

T
tokyo_ghoul4, 2021-06-10
@tokyo_ghoul4

hahaha) the file was opened for reading.
change 'w' to '+'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question