Execute a Python Script

Will Button
InstructorWill Button
Share this video with your friends

Social Share Links

Send Tweet

Python scripts can be executed by passing the script name to the python command or created as executable commands that can run stand-alone. You’ll learn how to create both in this lesson.

Let's create a script that we're going to execute with Python. We can do something as simple as say print("hello world!"). We can execute that by just typing Python and then passing in the name of the script and execute.

If we wanted to use Python 3, we need to call print as a function, save that, and then we can call it with the Python 3 command and again pass in the script name and it executes as well.

We can also make this a stand-alone executable. We'll include our shebang here and then pass in userbin env and tell it to find the Python environment. We need to mark that as executable, so we'll modify the attributes to include the executable bit. Now, we can type [inaudible 0:48] hello.py and it runs as well there.