17 th exercise in python3

17 th exercise in python3, line 8 -10

we could do these two on one line, how?

in_file = open(from_file)
indata = in_file.read()

this was the question, so i do it in one step
indata = open(from_file,‘r’)

It shows ERROR , can i know whats the problem??

indata = open(from_file,‘r’)

I don’t think you have actually read the file you’ve opened. ‘r’ sets the opened file ready for reading at the beginning of the file. You need to call a .read() function on it.

indata = open(from_file).read()

1 Like