python中try- except想要捕获syntaxerror,但是会报错,请问怎么改代码可以不报错并且正常输出错误类型
try- except捕获的是运行时(runtime)错误。明显的语法错误会被开发工具、预编译(生成pyc文件)拦截,因此不会被你的try- except捕获。