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

Simon Brunning SBrunning at trisystems.co.uk
Wed Feb 20 10:17:30 EST 2002


> From:	Russell Nelson [SMTP:nelson at crynwr.com]
> There are two Python ideoms that bother me:
> 
>     while 1:
>         line = file.readline()
>         if not line: break
 
As of 2.2, try

for line in file:
    line.whatever()
 
> 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.
 
Assignments and expressions are different things in Python, and I suspect
that they will remain so - see
<http://www.python.org/cgi-bin/faqw.py?req=show&file=faq06.030.htp>. I
*hope* so, certainly.

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning at trisystems.co.uk




-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list