How to execute Python inline from a bash shell

前端 未结 4 521
自闭症患者
自闭症患者 2020-12-24 11:22

Is there a Python argument to execute code from the shell without starting up an interactive interpreter or reading from a file? Something similar to:

perl          


        
4条回答
  •  伪装坚强ぢ
    2020-12-24 12:08

    This works:

    python -c 'print("Hi")'
    Hi
    

    From the manual, 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).
    

提交回复
热议问题