[Python-ideas] thoughts on generator.throw()

Aahz aahz at pythoncraft.com
Wed Mar 18 23:06:12 CET 2009


On Wed, Mar 18, 2009, Arnaud Delobelle wrote:
> On 18 Mar 2009, at 18:07, George Sakkis wrote:
>> On Wed, Mar 18, 2009 at 1:42 PM, Leif Walsh <leif.walsh at gmail.com>  
>> wrote:
>>>
>>> Why does raise have to be decently fast?
>>>
>>> In my average case, at least, it's encountered at most once per
>>> program execution.  Even if I was good about catching exceptions, the
>>> point is that they're _exceptional_ cases, so they shouldn't be
>>> happening very often.
>>
>> That's not always true; StopIteration comes to mind.
>
> But StopIteration is not usually raised explicitly.

This is a standard Python idiom:

        try:
            for field in curr_fields:
                for item in record[field]:
                    item = item.lower()
                    for filter in excludes:
                        if match(item, filter):
                            raise Excluded
        except Excluded: 
            continue 
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Programming language design is not a rational science. Most reasoning
about it is at best rationalization of gut feelings, and at worst plain
wrong."  --GvR, python-ideas, 2009-3-1



More information about the Python-ideas mailing list