0

For me it is necessary to make symbols in my code, So after building them(made by code in a list):

[W, U, V, x]

or

W, U, V, x

I need to turn them into sympy.symbols in a dynamic way not manually by coder :

x, y = symbols('x y') or symbols('x, y')

Is there any way to do it?

Z. K
  • 7
  • 4
  • What's wrong with `x, y = symbols('x y')`? I realise the symbols are created dynamically but any code that needs `x` and `y` as local Python variables could only be written by someone who knew what symbols there should be so why can't that person just write `x, y = symbols('x y')` at the start of their code? – Oscar Benjamin Aug 12 '22 at 13:28
  • It doesn't matter what strings are passed, but how each string can be a symbol dynamically is my problem. – Z. K Aug 12 '22 at 14:27
  • 1
    We are struggling to understand your goal. Please, take the time to edit the question and provide a minimal working example of what you would like to achieve... – Davide_sd Aug 12 '22 at 16:43

1 Answers1

0

To expose the symbols in the module as mentioned by Frank C on sympy unknown assignment

def symbol_references(in_list):
    for e in in_list:
        globals()[e] = Symbol(e)

symbol_references(['x', 'y'])
print(type(x))
print(type(y))
Z. K
  • 7
  • 4