On Fri, Jul 1, 2011 at 8:17 AM, Mani Chandra <[email protected]> wrote:
> Hi,
>
> Is it possible to save sympy expressions to disk and then load them later?
> For ex:
>
> filename = "equation"
> save(filename, expression)
> datafile = load(filename)
> expression = datafile.expression
>
> or something like that?
>
>
> Just like that (almost):
>>> eq
x + y**2
>>> pickle.dump(eq, file('eq.dat','w'))
>>> pickle.load(file('eq.dat'))
x + y**2
The nice thing about this is that assumptions on your variables are
preserved, too, so if x and y were designated as real, the x and y in the
equation you load will be real, too. Note, however, that if you start a new
session and load a saved expression this does not automatically recreate
python variables having the same name as the Symbols in the equation. To
save on the tedium of redefining those you could do something like this if
you last issued `eq = pickle.load(file('eq.dat'))` :
>>> [var(str(i), **i.assumptions0) for i in eq.atoms(Symbol)]
/Chris
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.