Converting dict containing SymPy objects to JSON

473 views
Skip to first unread message

TARUN GABA

unread,
Jun 20, 2014, 2:20:18 PM6/20/14
to sy...@googlegroups.com
Hi

I have a dict containing symbols as keys, mapped to float values. I need to convert it to JSON format(for passing to Javascript).

Here is an example dict:

constants = {l: 10.0, m: 10.0, g: 9.81}

python's json module cannot parse these symbols.What should be the best approach to implement this?

Thanks

Tarun Gaba

Aaron Meurer

unread,
Jun 20, 2014, 2:53:30 PM6/20/14
to sy...@googlegroups.com
You should probably just store the name of the symbol in the dictionary as a string. You may also want to do that for the floats if precision issues come up. 

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+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHAono2rMOfWi%3Dvx0Q1eKH2iQPQDhkEZ5HvTmAn94f2tpUpM-w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Matthew Rocklin

unread,
Jun 21, 2014, 12:48:48 PM6/21/14
to sy...@googlegroups.com

Sympy terms can be serialized/deserialized somewhat robustly with str and sympify.

Reply all
Reply to author
Forward
0 new messages