How to Run a Python Script

You can run Python scripts on Web Hosting Canada's servers by following these instructions:

  1. Your script must have a .py extension (ex: If you use other extensions, you must add a file called .htaccess in the same folder as the script, containing AddHandler cgi-script .py (replace .py by the other extension).
  2. The first line of the script (also called Shebang) must be #!/usr/bin/env python.
  3. Upload the script to the server, by granting it "744" as permissions.
  4. Run the script directly in your browser, or through the command-line interpreter as follows: python

Python script example (for testing):

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# to allow debugging
import cgitb
print "Content-Type: text/plain;charset=utf-8"


print "Hello World!"


Article ID: #HC5028

Was this answer helpful?