Home > other >  Open a text file, read each line with the interpretation of the book has discrepancy, please give di
Open a text file, read each line with the interpretation of the book has discrepancy, please give di

Time:03-19

Good bosses, reading test a piece of code:
the python version of the test is 3.8.5

With the open (" pi_digits. TXT ") as file_object:
Lines=file_object. Readline ()
Print (type (lines))
For the line in lines:
Print (line. The strip ())


The contents of a text file format is as follows:
3.1415926535
8979323846
2643383279

According to the book says lines is to keep a list of text file contents in each row,
Print the results consistent with content format text file
And the actual test results see screenshot:

CodePudding user response:

I think I should is

 lines.=file_object readlines () 



You missed a s


CodePudding user response:

Readline is read one line from index minimum, return to the text, the readlines is read all the rows returned a list
  • Related