What am I doing wrong here?

Andrew Bennetts andrew-pythonlist at puzzling.org
Mon Jun 30 03:32:34 EDT 2003


On Mon, Jun 30, 2003 at 02:42:11AM +0000, Bill C. Wong wrote:
> ################################
> def func( s ):
>     s1, s2 = s.split( ' ', 1 )
>     try:
>         raise s1
>     except "aaaa":
>         print 'except "aaaa"'
>     except:
>         print 'except:'
> 
> s = "aaaa "
> func( s )
> ################################
> If I manually assign s1 with s1 = "aaaa", then it works fine! What am I
> doing wrong here?

What's wrong is you're using string exceptions ;)

Try adding an 's1 = intern(s1)' before the raise statement -- string
exceptions are compared by identity, not equality, iirc.

I think you'd be better off using normal exceptions, though...

-Andrew.






More information about the Python-list mailing list