June 2017
Beginner
352 pages
8h 39m
English
Using read() for text is quite awkward, and thankfully Python provides better tools for reading text files line by line. The first of these is readline() function:
>>> g.readline()'What are the roots that clutch, what branches grow\n'>>> g.readline()'Out of this stony rubbish? '
Each call to readline() returns a single line of text. The returned lines are terminated by a single newline character, if there is one present in the file. The last line here does not terminate with a newline because there is no newline sequence at the end of the file. You shouldn't rely on the string returned by readline() being terminated by a newline. And remember that the universal newline support will have translated whatever the platform ...
Read now
Unlock full access