Skip to content
Advertisement

Convert list of strings SymPy to symbols and use in solveset

The post “How can I convert a list of strings into sympy variables?” discusses how to generate SymPy symbols from a list of strings. My question is what steps are needed to use these symbols x, y and z in SymPy calculations?

I tried something along the lines

JavaScript

but I get the error “NameError: name ‘x’ is not defined”. Any help is greatly appreciated.

Advertisement

Answer

You can create Python variables in the current namespace from a list of strings (or a string of space or comma separated names) with var:

JavaScript

In all cases, after issuing the var command you will be able to use variables that have been assigned SymPy symbols with the same name.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement