Code block literals

Vis Mike visionary25 at _nospam_hotmail.com
Fri Oct 10 15:35:28 EDT 2003


"Lulu of the Lotus-Eaters" <mertz at gnosis.cx> wrote in message
news:mailman.1065726763.15540.python-list at python.org...
> "Vis Mike" <visionary25 at _nospam_hotmail.com> wrote previously:
> |Something like this seems more logical to me:
> |for line in file('input.txt').lines:
> |    do_something_with(line)
> |for byte in file('input.txt').bytes:
> |    do_something_with(byte)
>
> Well, it's spelled slightly differently in Python:
>
>     for line in file('input.txt').readlines():
>         do_something_with(line)
>
>     for byte in file('input.txt').read():
>         do_something_with(byte)
>
> Of course, both of those slurp in the whole thing at once.  Lazy lines
> are 'fp.xreadlines()', but there is no standard lazy bytes.

xreadlines()? What kind of naming convention is that: :)

what about 'eachline()'?

> A method 'fp.xread()' might be useful, actually.  And taking a good idea
> from Dave Benjamin up-thread, so might 'fp.xreadwords()'.  Of course, if
> you were happy to write your own class 'File' that provided the extra
> iterations, you'd only need to capitalize on letter to get these extra
> options.

Mike






More information about the Python-list mailing list