[Tutor] NEWBIE is it possible to use HTML and Python together?

Jeff Shannon jeff@ccvcorp.com
Fri, 22 Mar 2002 10:08:13 -0800


> "Robert Garber" <garber@centralcatholic.org> wrote:
>
> I there any way to set the python up to run on a client side. I don think it's planned to run on the web, it's just his own little game. is there away to use something like py2exe to solve this?

Yes, you can do this.  Every machine that is to run this game must have Python and the win32all extensions installed.  Your best bet will be to install ActiveState's distribution, which comes
complete with all the extensions you'll need, out of the box.  You'll also need to be running Internet Exploder -- AFAIK, no other browser currently uses the Windows ActiveScripting engine, which is
what's required to use Python as a client-side script.  With these prerequisites in place, then it's a simple matter to write your scripts like this:

<script language="python">
def MyFunction():
    pass

def OtherFunction():
    # do stuff
    window.MyFunction()  # call other script function
    # do more stuff

</script>

You can pretty much use any valid Python in your scripts, but in order to be very effective, you'll have to have them manipulate the IE document model.  This is a pretty complicated topic, and you
might want to get a book about that.  I've used "Programming Internet Explorer 5" (Microsoft Press), and found it to be okay, and of course there's quite a bit of information available on
Microsoft's website.  A word of warning, though -- almost the code examples that you will see for doing client-side scripting will be in Javascript or VBScript, and you will have to translate.
That's usually not too hard -- watch out for parens vs brackets (VBS uses () in many places where Python uses [] ), and remember that Python will require explicitly specifying a lot more than VBS
does (what VBS refers to as, say, document.forms(0), Python will need to refer to as window.document.forms[0] ).

And of course, if there's anything that you're having problems with, you're welcome to ask about it here.  :)

Jeff Shannon
Technician/Programmer
Credit International