Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to simply execute a Python command without having to write a script or enter the interpreter. Is there a way that I could run something like:

python --execute "pow(12.31351,2)"

And have it simply print the result?

share|improve this question
up vote 6 down vote accepted

you can use -c arguments,like python -c "print 123",see python --help

usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
     -c cmd : program passed in as string (terminates option list)
share|improve this answer
Right, just needs a print statement to dump to stdout, gotcha. – Naftuli Tzvi Kay Sep 21 '11 at 22:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.