How to execute Python inline from a bash shell

前端 未结 4 520
自闭症患者
自闭症患者 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:06

    Another way is to you use bash redirection:

    python <<< 'print "Hi"'
    

    And this works also with perl, ruby, and what not.

    p.s.

    To save quote ' and " for python code, we can build the block with EOF

    c=`cat <

提交回复
热议问题