Error message: "io.UnsupportedOperation: not readable" in Python

0

I want to make a little program that reads a txt file and generates a list of lines of that file. The code that I have is the following:

f = open("rutas de archivos.txt","w",encoding="utf8")
linesfilelist = f.readlines()
f.close()

When executing this program I get the following error message:

Traceback (most recent call last):
File "C:\...", line 2, in <module>
linesfilelist = f.readlines()
io.UnsupportedOperation: not readable

What does it mean?

    
asked by Mr. Baldan 21.01.2017 в 19:31
source

1 answer

1

It's because you're making a mistake in how to use the file, instead of 'w' (write) use 'r' (read)

f = open("rutas de archivos.txt","r",encoding="utf8")
linesfilelist = f.readlines()
f.close()

that's how it works.

    
answered by 21.01.2017 / 20:43
source