Python Forum

Full Version: Attribute error - Sympy
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to use subs after using solve on a function, but the following error occurs. I have tried sympify and str but nothing changes. Any idea why?

x=Symbol('x')
f=2*x+2+y
x=solve(f,x)
g=x.subs(y,1)
Error:
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-120-a4eecf671499> in <module>() 2 f=2*x+2+y 3 x=solve(f,x) ----> 4 g=x.subs(y,1) AttributeError: 'list' object has no attribute 'subs'
solve() return a list and show LaTeX form in shell/editor/NoteBook that support this.
Can try sympify() on content in list first.
a = sympify(x[0])
g = a.subs(y,1)
>>> print(repr(g))
-3/2