How to Run a Python Script From a Shell

Guido van Rossum designed Python, a high-level, object-oriented programming language, for maximum human readability to help make programmers more productive. That is one reason programmers use the language for scripting. You can run Python scripts that you have downloaded from the Internet or written yourself from a shell, such as Bash.

Instructions

    • 1

      Open the Python script in a text editor, such as gedit in Gnome or Kate in KDE.

    • 2

      Insert the following line at the very top of the file:

      #!/usr/bin/python

    • 3

      Save the file and exit your editor.

    • 4

      Type the following command into the shell and press "Enter":

      chmod +x ScriptName.py

    • 5

      Type the script's path, or location within the file system, into your shell and press "Enter" to run it:

      ./ScriptName.py

Tips & Warnings

  • You can now run your python script from the shell anytime you want to by typing its path and pressing "Enter."

  • To run a script quickly one time only, type "python ScriptName.py" into your shell.

  • The "#" and "!" characters must be the first two characters of the file.

Related Searches:

References

Comments

Related Ads

Featured