Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Execute a Python Script

    Will ButtonWill Button

    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.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for 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 and it runs as well there.