While outside the scope of your question, it seems like you're doing
chemistry and that's my background so I can't help but mention that ChemPy
<https://github.com/bjodah/chempy>, which is based on SymPy, can parse
chemical formulas into substances and then return properties such as mass
(molecular weight):

>>> from chempy import Substance
>>> for chemical in ['Na','Cl','NaCl']:
     substance = Substance.from_formula(chemical)
    mass = substance.mass
     print(mass)
22.98976928
35.45
58.43976928000001

Jeremy Monat

P.S. I actually used that ChemPy functionality, along with SymPy, to
develop a cheminformatics app <http://sampler-flask.herokuapp.com/>.

On Sat, Aug 13, 2022 at 7:36 PM Aaron Meurer <asmeu...@gmail.com> wrote:

>
>
> On Sat, Aug 13, 2022 at 6:06 AM Zohreh Karimzadeh <z.karimza...@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 are trying to multiply the strings but you really want to multiply
> symbols. Something like Symbol(f"x{i}")*Symbol(f"x{i}").
>
> There should be no need to inject symbols into locals to do what you are
> trying to do. Symbols do not have to be assigned to a variable to work.
>
> Aaron Meurer
>
> --
>> 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/6e80be54-2134-460f-9125-08f0d99def73n%40googlegroups.com
>> <https://groups.google.com/d/msgid/sympy/6e80be54-2134-460f-9125-08f0d99def73n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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/CAKgW%3D6Lbbaid_unUZMHyO2MAhXfNvcwQdQW9sv4gjuZ2JFAFxQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/sympy/CAKgW%3D6Lbbaid_unUZMHyO2MAhXfNvcwQdQW9sv4gjuZ2JFAFxQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAO00iLizTJ-%3Dy617ypjoC5O%2B%2BDTb5eswMZQNwPSv9nFimoOPng%40mail.gmail.com.

Reply via email to