是否有 Python 参数可以在不启动交互式解释器或从文件读取的情况下从 shell 执行代码? 类似于:
perl -e 'print "Hi"'
最佳答案
这行得通:
python -c 'print("Hi")'
Hi
从手册中,man python
:
-c command Specify the command to execute (see next section). This termi- nates the option list (following options are passed as arguments to the command).
关于python - 如何从 bash shell 内联执行 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16908236/