How to process syntax errors
Pierre-Alain Dorange
pdorange at pas-de-pub-merci.mac.com
Mon Oct 10 11:44:38 EDT 2016
Chris Angelico <rosuav at gmail.com> wrote:
> Yes and no. Syntax errors are detected when the script is compiled, so
> you can't do something like this:
You're right, except that Python is never compiled, it was just checked
for syntax error before interpreting code.
>
> However, you can catch this at some form of outer level. If you're
> using exec/eval to run the code, you can guard that:
Your solution are OK, but that's not very "pythonic".
Python was not design to be used in such a way (intercepting syntax
error). There was hack to made somthing like requested but that only a
hack and should not be used in real world.
--
Pierre-Alain Dorange Moof <http://clarus.chez-alice.fr/>
Ce message est sous licence Creative Commons "by-nc-sa-2.0"
<http://creativecommons.org/licenses/by-nc-sa/2.0/fr/>
More information about the Python-list
mailing list