Raise X or Raise X()?

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Mar 12 06:37:48 EDT 2012


bvdp wrote:
> Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop:
>> try:
> for ...
> for ...
> for ...
> if match:
> raise StopInteration()
> else ...
>> except StopInteration:
> print "found it"
>
I prefer the raise X() version, it fulfils the zen of python :
"Special cases aren't special enough to break the rules.
There should be one-- and preferably only one --obvious way to do it."
I still wonder why they've added the class raise form, on which purpose.
JM


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /