python - 如何从 bash shell 内联执行 Python

标签 python shell inline execution

是否有 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/

相关文章:

Python 电话号码正则表达式

python - 列表理解与生成器表达式的奇怪 timeit 结果?

c++ - 内联类函数和共享库 (dll) 构建

c++ - 将内联加速 void a(string b) { cout << b; }

c++ - 静态库。导入和导出内联函数

python - 如何让 Python 进程使用所有 Docker 容器内存而不被杀死?

linux - 用于运行命令的 Bash 脚本

c - shell C中的动态分配和段错误

bash - 磁盘使用格式

python - 在 python 中绘制没有零值的直方图?