Success calling functions from Python
Thanks to Mark Hammond at ActiveState for figuring out how python
can call a
function from another language in a .wsf file. It turns out all you have to
do is preface the function with "globals." .i.e.
"globals.MessageBox(strText1 + "\n" + strText2)".
Below is a (now) working example and a quote from Mark on how he figured it
out. He suggests that the same approach could be used for ASP. For more
details on using Python in Windows see his book "Python Programming on
Win32". Highly recommended!
<!-- HelloWorld.wsf -->
<script id="Python" language="Python">
strText1 = "Hello, world!"
strText2 = "I'm Text From Python."
globals.MessageBox(strText1 + "\n" + strText2)
From Mark Hammond: "For ASP, I don't know what the object is - you will need
to find that in the IIS documentation. However, if you don't mind hacking, I
have a tip - this is how I worked out "wsh" uses "global" :-)
If you open win32comext\axscript\client\pyscript.py, search for:
def RegisterNamedItem(self, item):
Add the following 2 lines as the first 2 lines:
print "** RegisterNamedItem", item.name
Then, start Pythonwin and select "Trace Collector Debugging Tool". Restart
IIS, and run some Python code. When I did this for WSH, I saw the following:
** RegisterNamedItem scriptlet
** RegisterNamedItem globals
** RegisterNamedItem WSH
** RegisterNamedItem WScript
And guessed "globals" would be the one. It was :-)"