Newby: how to transform text into lines of text

Sion Arrowsmith siona at
Mon Jan 26 13:22:18 CET 2009

Diez B. Roggisch <deets at> wrote:
> [ ... ] Your approach of reading the full contents can be 
>used like this:
>content =
>for line in content.split("\n"):
>     print line

Or if you want the full content in memory but only ever access it on a
line-by-line basis:

content = a.readlines()

(Just because we can now write "for line in file" doesn't mean that
readlines() is *totally* redundant.)

\S -- siona at --
   "Frankly I have no feelings towards penguins one way or the other"
        -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump

More information about the Python-list mailing list