En Wed, 07 Nov 2007 01:53:31 -0300, [EMAIL PROTECTED]  
<[EMAIL PROTECTED]> escribió:

> This works great except for syntax errors.  Any idea why your solution
> doesn't catch those?
>
> Here's the output it gives me, followed by the code I'm using (running
> in Python 2.5):
>
> Traceback (most recent call last):
>   File "traceback_test.py", line 27, in gamma
>     exec s in {}
>   File "<string>", line 6
>      print hi'
>              ^
>  SyntaxError: EOL while scanning single-quoted string

Which would be your expected output?
Syntax errors happen when the code is *compiled*, before it gets executed.
You may catch syntax errors before even trying to execute the code, if you  
do it in two steps:

     try:
         ccode = compile(s, filename, 'exec')
     except SyntaxError:
         ...show the error appropiately...
         ...abort execution...
     try:
         exec ccode in {}
     except Exception, e:
         ...handle exception...


-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to