Mar-11-2019, 12:00 AM
Since your code snippet is unformatted, I can just suppose what exactly code you ran.
def main(): from sympy.abc import x, y code = """ x + y + x """ try: e = eval(code) except SyntaxError: print ("errores") print(e) if __name__ == "__main__": main()
Error:UnboundLocalError: local variable 'e' referenced before assignment
This is because the expression to be evaluated (the code
string) includes spaces that causes IndentationError
. IndentationError
, in turn, is subclass of SyntaxError
, so, print(errors)
is executed and variable e
is not being assigned. This is why UnboundLocalError
raised.