`var` will inject the symbols into the namespace. But you could also use 
parse_expr and pass it a dictionary with the symbols to use:

from sympy import parse_expr, symbols, var
v =  ['xa', 'xb']
xa, xb = map(var, v)
ok = xa*xb
better = parse_expr('xa*xb', local_dict=dict(zip(v, symbols(v))))

Chris
/c
On Saturday, August 13, 2022 at 7:06:01 AM UTC-5 z.kari...@gmail.com wrote:

> Dear sympy
> Thank millions  for sharing and caring!
> I need to create and use symbols in dynamic way. Infact symbols are made 
> based on user input and used in code so I must use f'strings to make them.
> As shown below:
> L=[ 'xCl', 'xNa']
> for j in range(len(L)):
>      locals()[L[j]] = sympy.symbols(L[j])
> ss = xCl * xNaCl
> i = 'Na'
> j='Cl'
> gg =f"x{i}"* f"x{j}" 
> print('gg', gg)
> But I got the following error
> TypeError: can't multiply sequence by non-int of type 'Symbol'
> Could possibly let me know how can do it??
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/794087ee-1239-4ace-958c-fbf0a6040c66n%40googlegroups.com.

Reply via email to