I would like to read a formula from text input and than process it further with sympy. I did not find a elegant solution for that. What works is the following work around using an intermediate script that is imported. I thought there might be a simpler and more elegant way. import sympy import string import re splits = '[\]\[ ()/*-=><^:]' #the formula that might come from text file or textbox of a gui f = 'fx = (x-2 * z)/f' lst = re.split(splits, f) #make temp script to be imported f_tmp = open('sympy_symbols.py', 'w') f_tmp.write('import sympy\n') for s in lst: if s != '' and s[0] in string.letters: f_tmp.write('%s = sympy.Symbol("%s")\n' % (s, s)) f_tmp.write(f) f_tmp.close() #import temp script from sympy_symbols import * print fx dfdx = sympy.diff(fx, x) print dfdx
Many thanks for any suggestions janwillem -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@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.