简体   繁体   English

在python中捕获EOL异常

[英]Catch EOL exception in python

I m trying to execute some code statement dynamically in Python using exec()我正在尝试使用exec()在 Python 中动态执行一些代码语句

The code statement is accepted from the user input.从用户输入中接受代码语句。

How do I handle the EOF exception that occurs when the string quotes are not closed?如何处理字符串引号未关闭时发生的EOF异常?

For eg.例如。

 >> exec('if 5 > 1: print "5 is greater)
    # of course, this will raise an exception, 
    # how do I handle this 

How do I handle such cases, using a try-catch ?我如何处理这种情况,使用try-catch What exception should I be looking for here?我应该在这里寻找什么exception

EOFError is what you are looking for EOFError 就是你要找的

This link should help you http://docs.python.org/2/library/exceptions.html此链接应该可以帮助您http://docs.python.org/2/library/exceptions.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM