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

Georg Brandl g.brandl at gmx.net
Wed Dec 29 16:18:52 CET 2010


Am 29.12.2010 15:46, schrieb Michael Foord:

>     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).
> 
> That would be great. I did worry that changing the output would be backwards
> incompatible with code that shells out to Python using "-c", so a different
> command line option would be great. So long as it works with multiple statements
> (semi-colon separated) like the current "-c" behaviour.

Hey, what about this little module:

import sys
for x in sys.argv[1:]:
    exec compile(x, '<cmdline>', 'single')

Then:

$ python -me '1+1; 2+2'
2
4

Georg




More information about the Python-ideas mailing list