Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sympy
#8
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.
Reply


Messages In This Thread
sympy - by psosmol - Mar-09-2019, 11:16 AM
RE: sympy - by scidam - Mar-09-2019, 11:30 AM
RE: sympy - by psosmol - Mar-09-2019, 03:55 PM
RE: sympy - by stullis - Mar-09-2019, 05:33 PM
RE: sympy - by psosmol - Mar-09-2019, 06:05 PM
RE: sympy - by scidam - Mar-10-2019, 06:20 AM
RE: sympy - by psosmol - Mar-10-2019, 08:35 AM
RE: sympy - by scidam - Mar-11-2019, 12:00 AM
RE: sympy - by psosmol - Mar-11-2019, 10:23 AM
RE: sympy - by scidam - Mar-11-2019, 11:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python sympy problem for symbolic equation definition joellapointe_engineering 0 283 Mar-24-2024, 11:09 PM
Last Post: joellapointe_engineering
  Sympy nonlinsolve does not return explicit solution axelle 1 2,280 Jan-20-2021, 11:38 AM
Last Post: Serafim
  plot differential equation sympy dan_adi 0 3,034 Oct-13-2020, 10:44 AM
Last Post: dan_adi
  Attribute error - Sympy VictorG8 1 5,046 Apr-09-2020, 06:03 PM
Last Post: snippsat
  How to use list of symbols for sympy calculation in python? tanmaybhise 1 2,834 Mar-01-2020, 10:36 PM
Last Post: Gribouillis
  Next zero of a function on sympy VicenteM 0 2,107 Aug-21-2019, 04:58 PM
Last Post: VicenteM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020