How to do this in Python...

Simo Salminen look at sig.invalid
Thu Jan 23 19:48:14 EST 2003


* Paul Rubin [23 Jan 2003 15:09:21 -0800]
> Tim Peters suggested one a few days ago:
> 
>    if [match for match in [re.match(pattern,string)]][0]:
>         # do something with match object

and from cookbook:
<clip>

Not recommended, in any case, is the following abuse of list format
as comprehension
syntax:

while [line for line in (file.readline(),) if line]:
  process(line)

It works, but it is unreadable and error-prone.

</clip>

i think the conclusion applies to this case too.

-- 
simo <dot> salminen <at> iki <dot> fi




More information about the Python-list mailing list