Option for python cmd to have interactive behavior

When use in interactive more, the return value of an expression gets printed

>>> 1+1
2

Is there is there some option to have this behavior when using it as a command?

For example, a flag of configuration to make python -c "1+1" behave as python -c "print(1+1)" would do.

I don’t know any such option. I just looked around in the command line options and env settings docs, and still didn’t find anything. For simple commands you could make your own python :slight_smile:

#!path_to_your_python_executable
import sys
import os
from math import *
sys.path[0:0] = os.getcwd()
args = " ".join(sys.argv[1:])
print(eval(args))
$ ./mypython pi + e
5.859874482048838
1 Like

No, in batch mode one must explicitly print. Adding -i (before -c is also used) puts python in interactive mode after executing the indicated code in batch mode.