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?
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
+ 1
Have you got to this part of the Python course yet? https://www.sololearn.com/learn/Python/2445/
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