If I load a text file from Python and read it once, can't I read it with another read line?

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

Hi, how are you?

Text file

For example, it is called as followsHmmm

data = open('text.txt')  
aa=data.read()
bb=data.readline()

If you use these two,

In the first aa, print(aa), the contents of the text file appear

The second bb seems to be read without error, but if you print (bb), It looks like there's nothing.

[] 

If I load a text file from Python and read it once, can't I read it with another read line?

If I want to use two according to the situation, should I reopen the text file every time?

python

2022-09-20 10:59

1 Answers

The seek method allows you to adjust the position of the file pointer. It would be helpful if you look for file pointers and seek methods.


2022-09-20 10:59

If you have any answers or tips


© 2022 pinfo. All rights reserved.