a little more help with python server-side scripting

Ben Cartwright bencvt at gmail.com
Tue Feb 21 20:28:38 EST 2006


John Salerno wrote:
> I contacted my domain host about how Python is implemented on their
> server, and got this response:
>
> -------------------
> Hello John,
>
> Please be informed that the implementation of python in our server is
> through mod_python integration with the apache.
>
> These are the steps needed for you to be able to run .py script directly
> from browser for your webpage:
>
> 1. Please use the below mentioned path for python:
> #!/usr/bin/env python
>
> Furthermore, update us with the script path, so that we can set the
> appropriate ownership and permissions of the script on the server.
>
> If you require any further assistance, feel free to contact us.
> -----------------------
>
> Unfortunately, I don't completely understand what it is I need to do
> now. Where do I put the path they mentioned? And what do they mean by my
> script path?


The Python tutorial should fill in the blanks
(http://www.python.org/doc/tut/node4.html):
> 2.2.2 Executable Python Scripts
>
> On BSD'ish Unix systems, Python scripts can be made directly executable,
> like shell scripts, by putting the line
>
>   #! /usr/bin/env python
>
> (assuming that the interpreter is on the user's PATH) at the beginning
> of the script and giving the file an executable mode. The "#!" must be
> the first two characters of the file. On some platforms, this first line
> must end with a Unix-style line ending ("\n"), not a Mac OS ("\r") or
> Windows ("\r\n") line ending. Note that the hash, or pound, character,
> "#", is used to start a comment in Python.

This answers your first question.  Put the #! bit at the top of your
.py script.  This way the web server will know how to run the script.

> The script can be given a executable mode, or permission, using the
> chmod command:
>
>   $ chmod +x myscript.py

And this answers your second.  Your host needs to know the path to your
script so they can use chmod to make it executable.

--Ben




More information about the Python-list mailing list