iterating over lines in a file

nobody no at bo.dy
Thu Jul 20 23:57:00 EDT 2000


"Roger Upole" <rupole at compaq.net>, in
<vnLd5.27741$r9.839310 at news.easynews.com>:

> I must take exception to your insistence that
>    "Everything should be done ONCE, and only ONCE.  In ONE
>    place in the code."
> Besides sounding didactic, it is also completely false.  In many cases,
> an initial read is necessary to determine how (or even if) the rest of a
> file will be processed.

true, but i think you will find that most of these cases are reading a
header of (usually) an entirely different format from the rest of the
data. doing things as few times as possible, in as few places as
possible, is nothing more than simple abstraction - or, as i like to
think about it, code hygiene.

now, this newbie has run into another perl idiom he'd like to figure out
how to rewrite in python - "while (<FILE>) { print; }" - and, by extension,
how to get python to print the string i hand it, the whole string i hand it,
and nothing but the string i hand it? i despise machines trying to second-
guess my intentions, and silly little print statements trying to be clever
with their arguments are nothing more than that.

even so, python is still worth trying to learn, IMO. its ways of dealing
with regexps and substitution might not be as handy and convenient as
perl's operators, but the re module seems to me to be more "programmable"
somehow, easier to write code around. i like it, i just wish its functions
would be more consistent about what sort of regexps they want - either all
compiled or all not compiled; i'm seeing some wanting one and some the
other, for some reason. might be just my system, i suppose...




More information about the Python-list mailing list