Success calling functions from Python 
Author Message
 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!

Don

<?xml version="1.0"?>
<!-- HelloWorld.wsf -->
 <job>
  <script language="VBScript">
<![CDATA[
      Function MessageBox(strText)
         MsgBox strText
      End Function
]]>
  </script>

  <script id="Python" language="Python">
<![CDATA[
strText1 = "Hello, world!"
strText2 = "I'm Text From Python."
globals.MessageBox(strText1 + "\n" + strText2)
]]>
  </script>
 </job>

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:

import win32traceutil

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 :-)"



Sun, 18 May 2003 03:00:00 GMT  
 Success calling functions from Python

Great! Now I can call functions across all languages with one exception--I
get a "call of non-function (type int)" error when I try to call a Perl sub
from Python.

=-=-=
Steve
-=-=-


Quote:
> 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!

> Don

[example snipped]


Sun, 18 May 2003 03:00:00 GMT  
 Success calling functions from Python
Steve, I passed your problem on to Mark Hammond.  Here's his reply

Don

**************************************************

You may find the call is being made when you reference the _name_ of the
function.

eg:

ob.foo # actually calls the function, so

ob.foo() # calls the function, then tries to call the result.

If the function returns an integer (likely) this is what you get!

Mark.


Quote:
> Great! Now I can call functions across all languages with one exception--I
> get a "call of non-function (type int)" error when I try to call a Perl
sub
> from Python.

> =-=-=
> Steve
> -=-=-



> > 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!

> > Don

> [example snipped]



Mon, 19 May 2003 13:17:27 GMT  
 Success calling functions from Python
He's right. However, that makes it pretty hard to pass arguments to
the Perl sub. :-(

=-=-=
Steve
-=-=-


Quote:
> Steve, I passed your problem on to Mark Hammond.  Here's his reply

> Don

> **************************************************

> You may find the call is being made when you reference the _name_ of the
> function.

> eg:

> ob.foo # actually calls the function, so

> ob.foo() # calls the function, then tries to call the result.

> If the function returns an integer (likely) this is what you get!

> Mark.



> > Great! Now I can call functions across all languages with one
exception--I
> > get a "call of non-function (type int)" error when I try to call a Perl
> sub
> > from Python.

> > =-=-=
> > Steve
> > -=-=-



> > > 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!

> > > Don

> > [example snipped]



Mon, 19 May 2003 03:00:00 GMT  
 Success calling functions from Python
Perhaps you could add a Perl function that simply calls the sub.  Then you
could call the function from Python.


Quote:
> He's right. However, that makes it pretty hard to pass arguments to
> the Perl sub. :-(

> =-=-=
> Steve
> -=-=-



> > Steve, I passed your problem on to Mark Hammond.  Here's his reply

> > Don

> > **************************************************

> > You may find the call is being made when you reference the _name_ of the
> > function.

> > eg:

> > ob.foo # actually calls the function, so

> > ob.foo() # calls the function, then tries to call the result.

> > If the function returns an integer (likely) this is what you get!

> > Mark.



> > > Great! Now I can call functions across all languages with one
> exception--I
> > > get a "call of non-function (type int)" error when I try to call a
Perl
> > sub
> > > from Python.

> > > =-=-=
> > > Steve
> > > -=-=-



> > > > 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!

> > > > Don

> > > [example snipped]



Mon, 19 May 2003 03:00:00 GMT  
 Success calling functions from Python
I don't have a real-world need to call a Perl sub from Python. I just have a
test .wsf file that has functions in all the AXS languages I have installed
and script blocks in all these languages that call each function. If I had
to, I could write a J/VBScript wrapper function--I can call them with
arguments from Python.

=-=-=
Steve
-=-=-


Quote:
> Perhaps you could add a Perl function that simply calls the sub.  Then you
> could call the function from Python.



> > He's right. However, that makes it pretty hard to pass arguments to
> > the Perl sub. :-(

> > =-=-=
> > Steve
> > -=-=-



> > > Steve, I passed your problem on to Mark Hammond.  Here's his reply

> > > Don

> > > **************************************************

> > > You may find the call is being made when you reference the _name_ of
the
> > > function.

> > > eg:

> > > ob.foo # actually calls the function, so

> > > ob.foo() # calls the function, then tries to call the result.

> > > If the function returns an integer (likely) this is what you get!

> > > Mark.



> > > > Great! Now I can call functions across all languages with one
> > exception--I
> > > > get a "call of non-function (type int)" error when I try to call a
> Perl
> > > sub
> > > > from Python.

> > > > =-=-=
> > > > Steve
> > > > -=-=-



> > > > > 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!

> > > > > Don

> > > > [example snipped]



Mon, 19 May 2003 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Calling Ghostscript from Python

2. Calling a sub or function using a variable through another sub or function

3. Postscript converter in Python

4. TCL/Python

5. .reg file for Python ?

6. WSH vs Python

7. KickAgent via wsh/python

8. Expose Python library to PerlScript using WSC

9. Possible to use Python and WSH?

10. Using Python with WSH

11. JScript vs. Python

12. How to call a function across frames

 

 
Powered by phpBB® Forum Software