two ideoms at one blow: line-reading and regexp-matching
Terry Reedy
tjreedy at home.com
Wed Feb 20 11:28:49 EST 2002
"Russell Nelson" <nelson at crynwr.com> wrote in message
news:m2vgcs5hgf.fsf at desk.crynwr.com...
> There are two Python ideoms that bother me:
>
> while 1:
> line = file.readline()
> if not line: break
>
> and:
>
> matched = re.match(r'egexp(.*)', line)
> if matched:
> print matched.group(1)
>
> I'd really, really like it if you could do one(1) assignment within
> the boolean expression in a while and an if. Like this:
>
>
> while line = file.readline():
>
> and:
>
> if matched = re.match(r'egexp(.*)', line):
> print matched.group(1)
>
> I just think it would be easier to read programs if they could be
> written like this. Should I write up a PEP or has this already been
> discussed and dismissed?
Both have been discussed (the former ad nauseum) and dismissed for at
least the present. You could certainly find some thru groups.google.
Don't know if there is a PEP documenting any of the discussion.
Terry J. Reedy
More information about the Python-list
mailing list