[Python-Dev] PEP 340: Breaking out.

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Wed May 4 18:23:03 CEST 2005


Paul Moore wrote:
> On 5/4/05, Alex Martelli <aleaxit at yahoo.com> wrote:
>> 
>> On May 4, 2005, at 01:57, Paul Moore wrote:
>> >
>> > I can't think of a reasonable condition which wouldn't involve reading
>> > the file - which either involves an inner loop (and we already can't
>> > break out of two loops, so the third one implied by the opening block
>> > makes things no worse), or needs the whole file reading (which can be
>> 
>> Looking for a file with a certain magicnumber in its 1st two bytes...?
>> 
>> for name in filenames:
>>     opening(name) as f:
>>         if f.read(2) == 0xFEB0: break
>> 
>> This does seem to make real-life sense to me...
> 
> Yes, that'd do. I can't say I think it would be common, but it's a
> valid case. And the workaround is the usual messy flag variable:
> 
> for name in filenames:
>     found = False
>     opening(name) as f:
>         if f.read(2) == 0xFEB0: found = True
>     if found: break

Is there anything we could do about this?

Reinhold

-- 
Mail address is perfectly valid!



More information about the Python-Dev mailing list