7.1. Python scripts

Python scripts run with Karrigell are ordinary Python scripts, except that the print statement sends the output to the client's browser instead of the console window. Therefore you'll have to write HTML code if you need the correct formatting ; for a minimal table you'll have to write something like

print "<TABLE>"
print "<TR>"
print "<TD>Name</TD>"
print "<TD>Address</TD>"
print "</TR>"
print "</TABLE>"

or, using the multi-line Python syntax :

print """<TABLE>
      <TR>
        <TD>Name</TD>
        <TD>Address</TD>
      </TR>
    </TABLE>"""
or if you want to use the HTMLTags module :

from HTMLTags import *
print TABLE(TR(TD("Name")+TD("Address")))

If you write Python scripts that musn't be executed by Karrigell (for instance because they have a GUI-based interaction with the user) you can include this code at the top of your script :

try:
    SCRIPT_END
except NameError:
    pass
else:
    print "This script can't be executed by Karrigell"
    raise SCRIPT_END
(... rest of your script here ...)

Since SCRIPT_END is in the namespace of Python scripts when executed in Karrigell, the execution stops in this case ; when run from the command line, a NameError is raised, and is ignored by the script