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"'
Using the python Command To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World!
We can make use of the bash script to run the Python script in macOS/Ubuntu. Both these operating systems support bash scripts. Let's see the steps to run Python scripts using a bash script. Open any text editor.
The most basic and easy way to run a Python script is by using the python command. You need to open a command line and type the word python followed by the path to your script file, like this: python first_script.py Hello World! Then you hit the ENTER button from the keyboard and that's it.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With