Newby: how to transform text into lines of text

Sion Arrowsmith siona at chiark.greenend.org.uk
Mon Jan 26 07:22:18 EST 2009


Diez B. Roggisch <deets at nospam.web.de> wrote:
> [ ... ] Your approach of reading the full contents can be 
>used like this:
>
>content = a.read()
>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 chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
   "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