Sympifyin string with superscripts

188 views
Skip to first unread message

darmend...@outlook.com

unread,
Jan 25, 2018, 10:18:47 PM1/25/18
to sympy
I am trying to sympify a string like these

    str1="a^0_0"
    ns={}
    ns['a^0_0']=Symbol('a^0_0')
    pprint(sympify(str1,locals=ns))

But I get the following error

    Traceback (most recent call last):
      File "cuaterniones_basic.py", line 114, in <module>
        pprint(sympify(str1,locals=ns))
      File "/usr/local/lib/python2.7/dist-packages/sympy/core/sympify.py", line 356, in sympify
        raise SympifyError('could not parse %r' % a, exc)
    sympy.core.sympify.SympifyError: Sympify of expression 'could not parse u'a^0_0'' failed, because of exception being raised:
    SyntaxError: invalid syntax (<string>, line 1

How can get the symbol I want?

Leonid Kovalev

unread,
Jan 26, 2018, 1:50:18 AM1/26/18
to sy...@googlegroups.com
To avoid duplication of effort, it should be mentioned that this was
also posted on Stack Overflow:
https://stackoverflow.com/questions/48454848/sympy-sympifying-strings-containing-expressions-with-superscripts
Reply all
Reply to author
Forward
0 new messages