Basic execution - SymPy

27 views
Skip to first unread message

jiju

unread,
Apr 21, 2014, 2:19:06 PM4/21/14
to sy...@googlegroups.com
Hi,

I have successfully installed SymPiy. Consider the following python  script test.py with output -sin(x) as expected

from sympy import *
var('x')
print diff(cos(x), x)

I would like to pass diff(cos(x), x) as a command line argument to python  script as python test.py  diff(cos(x), x). Could you help me in how to execute this then?

I tried to use print os.system(sys.argv[1]) which is not working! Thanks in advance



Ondřej Čertík

unread,
Apr 21, 2014, 2:25:49 PM4/21/14
to sympy
Just do this:

import sys
from sympy import *
var("x")
print eval(sys.argv[1])


And call it like this (don't forget the quotes):

$ python test.py "diff(cos(x), x)"
-sin(x)


>
>
>
> --
> 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/adaf9c05-e5c3-4152-b13d-95bfd62ef6e4%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

jiju

unread,
Apr 21, 2014, 2:29:05 PM4/21/14
to sy...@googlegroups.com
Thanks Ondrej Certík, it worked !.
Reply all
Reply to author
Forward
0 new messages