On Jul 10, 2013, at 9:17 AM, Amit Saha <amitsaha...@gmail.com> wrote:
> On Wed, Jul 10, 2013 at 1:24 AM, Aaron Meurer <asmeu...@gmail.com> wrote: >> Yep, strings often (but won't always!) work as input. See >> https://github.com/sympy/sympy/wiki/Idioms-and-Antipatterns#strings-as-input. > > Thanks. Yeah, I have learned that from one of my earlier posts to the > forum. In this case it should be fine, I guess. > In fact, I think I made my original query ambiguous: I was really > asking about passing the symbol to be solved for as a string, > *not* the expression. Even then, you should avoid string. Many arguments to many SymPy functions accept strings like this, but it's bad practice to use them. > > Is this a better approach: > >>>> expr = 'x*2 + 5 + y' >>>> expr=sympify(expr) >>>> for symbol in expr.atoms(Symbol): > ... if str(symbol)=='x': > ... solve(expr, symbol) > ... > [-y/2 - 5/2] > > So, I look for the symbol I want to solve for and then invoke solve > using the symbol itself, this having to avoid passing a string. It's better to look at symbol.name. Two symbols can have the same string representation but be unequal. Aaron Meurer > > -- > http://echorand.me > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sympy+unsubscr...@googlegroups.com. > To post to this group, send email to sympy@googlegroups.com. > Visit this group at http://groups.google.com/group/sympy. > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy. For more options, visit https://groups.google.com/groups/opt_out.