That's sound great because that's the way I do. Best regards. Christophe.
2009/12/8 Aaron S. Meurer <asmeu...@gmail.com> > The problem is using strings directly in functions. The proper way to do > this is to convert the string to a SymPy object first with the sympify() > function. So for example, this would be perfectly legitimate: > > from sympy import sympify, diff, S > from sympy.core.sympify import SympifyError # Note to fellow developers: > why isn't this being imported with the above > expr = "2*x**3+5" > variable = "x" # You will want to get the variable of differentiation > try: > sexier = sympify(expr) > svariable = S(var) # S is the same as sympify > except SympifyError: > print "Could not parse expression." > print diff(sexpr, svariable) > > Using strings directly in functions is not a good idea among other things > because not all functions support it. For example: > > >>> simplify("x + 1") > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "sympy/simplify/simplify.py", line 1318, in simplify > expr = Poly.cancel(powsimp(expr)) > File "sympy/simplify/simplify.py", line 1121, in powsimp > if expr.is_Pow: > AttributeError: 'str' object has no attribute 'is_Pow' > > Aaron Meurer > On Dec 8, 2009, at 5:51 AM, Christophe BAL wrote: > > Hello, > I would like to use sympy in the following way : > > 1. The user types some formula like for example "2*x**3+5". > 2. My little program named test.py must have to differentiate this > formula. > > The problem is that the formula is known as a string. > Is there a way to not used string so as to work with the user's formula ? > > Best regards. > Christophe. > > PS : I send this message because Ondrej said to not use string in some > messages. > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to sy...@googlegroups.com. > To unsubscribe from this group, send email to > sympy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to sy...@googlegroups.com. > To unsubscribe from this group, send email to > sympy+unsubscr...@googlegroups.com <sympy%2bunsubscr...@googlegroups.com>. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sy...@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.