simple try/except question

Tim Chase python.list at tim.thechases.com
Mon Oct 29 17:02:24 CET 2007


> Is the behavior below expected?
> If so, why is the exception not caught?
> Thanks,
> Alan Isaac
> 
>>>> x,y='',''
>>>> try: x/y
> ... except TypeError: print 'oops'
> ...
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: unsupported operand type(s) for /: 'str' and 'str'

A typo in your code?  It works for me(tm)...

Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
information.
 >>> x,y = '',''
 >>> try: x/y
... except TypeError: print 'oops'
...
oops

-tkc






More information about the Python-list mailing list