[Python-ideas] python -c "..." should output result like the interpreter

Paul Moore p.f.moore at gmail.com
Wed Dec 29 15:40:18 CET 2010

On 29 December 2010 13:36, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
> Hello all,
> I often use python as a calculator or for simple operations using -c. It
> would be enormously useful if python -c "..." would output on stdout the
> result of the last evaluated expression in the same way that the interactive
> interpreter does.
> The following outputs nothing:
>     python -c "12 / 4.1"
> So you always have to prefix expressions with print to see the result.

I like the idea, but that's a fairly big semantic change. What about
adding an -e option that takes an expression, and prints its value? So
you'd have

    python -e "12 / 4.1"

(AFAICT, -e is unused at present).


More information about the Python-ideas mailing list