two ideoms at one blow: line-reading and regexp-matching

Russell Nelson nelson at crynwr.com
Wed Feb 20 09:57:36 EST 2002


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?

-- 
-russ nelson              http://russnelson.com | Crypto without a threat
Crynwr sells support for free software  | PGPok | model is like cookies
521 Pleasant Valley Rd. | +1 315 268 1925 voice | without milk.
Potsdam, NY 13676-3213  | +1 315 268 9201 FAX   | 



More information about the Python-list mailing list