0

Can we store variable in file while open the file in read mode?

Using the open() function, open the test.txt file in reading mode and store it in the variable called file_2 is this possible ? If yes please throw me some idea how do we do it?

26th Sep 2020, 7:36 AM
Abhi
Abhi - avatar
3 Answers
+ 2
You can do it like: f = open('test.txt','r') temp = f.read() # do something with temp... f.close() "f" is the file pointer to access and operate the file. "temp" is a variable that is used to store the content of the file
26th Sep 2020, 9:37 AM
Lothar
Lothar - avatar
+ 1
Have you got to this part of the Python course yet? https://www.sololearn.com/learn/Python/2445/
26th Sep 2020, 11:12 AM
David Ashton
David Ashton - avatar
0
Hmm we always do this freind Var = open("file.txt","r") Will open up file and store it in Var so that you can use it later
26th Sep 2020, 8:03 AM
Ayush Kumar
Ayush Kumar - avatar