How to execute Python inline from a bash shell
问题 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 -e 'print "Hi"' 回答1: 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). 回答2: Another way is to you use bash redirection: python <<< 'print "Hi"' And this works also