[Tutor] Browser-based Python Interpreter

alan.gauld@bt.com alan.gauld@bt.com
Fri, 7 Sep 2001 15:26:25 +0100


------_=_NextPart_001_01C137A9.1367B950
Content-type: text/plain; charset="iso-8859-1"

there was a mail abt NT related automation and somebody mentioned WSH. 
I have installed it. Alan mentions about "Active Scripting support for 
Python". Is there another component that I need to install after WSH 
so that I can proceed ?  

Once you have WSH and Python installed you need to
also install the winall package(already done if you 
used the ActiveState Python in the first place)
 
Now you can take either of two routes:
 
1) Install activeScripting by running a file within the 
   winall package. This allows you to write .pys WSH 
   scripts and run them using wscript.exe or cscript.exe
 
2) Just use winall's native COM facilities to create 
   the WSH COM objects - this seems to be Mark Hamonds 
   personal favourite method.
 
Using method 1 and stealing an example from Marks Win32 
book we get the following example:
 
######## wshtest.pys #######
WScript.Echo('The script is: ',WScript.SciptName) # Use WSH natively
if len(WScript.Arguments):
   wshell = WScript.CreateObject("WScript.Shell")
   wshell.Run("notepad.exe " + WScript.Arguments(0))
else:
   WScript.Echo('No arguments passed')
 
############################
 
Run it by entering 
C:\> cscript wshtest.pys  foo bar 
at a DOS prompt or
C:\> wscript wshtest.pys baz
to get GUI style messages
 
 
Doing the same in native Python requires a mix of WSH 
and raw Python:
 
######## wshtest.py ########
from win32com.client import Dispatch
import sys
 
print 'The script is: ',sys.argv[0]

if len(sys.argv) > 1:
   wshell = Dispatch("WScript.Shell")
   wshell.Run("notepad.exe "+sys.argv[1])
else:
   print 'No arguments passed'

############################
 
HTH,
 
Alan g
 


------_=_NextPart_001_01C137A9.1367B950
Content-type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>RE: [Tutor] Browser-based Python Interpreter</TITLE>

<META content="MSHTML 5.00.3013.2600" name=GENERATOR></HEAD>
<BODY>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <P><FONT size=2>there was a mail abt NT related automation and somebody 
  mentioned WSH.</FONT> <BR><FONT size=2>I have installed it. Alan mentions 
  about "Active Scripting support for </FONT><BR><FONT size=2>Python". Is there 
  another component that I need to install after WSH</FONT> <BR><FONT size=2>so 
  that I can proceed ?</FONT>&nbsp;<FONT color=#0000ff face="Courier New" 
  size=2><SPAN class=150565113-07092001>&nbsp;</SPAN></FONT></P></BLOCKQUOTE>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>Once you have WSH and Python installed you need 
to</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>also install the winall package(already done if you 
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>used the ActiveState Python in the first 
place)</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>Now you c</SPAN></FONT><FONT color=#0000ff 
face="Courier New" size=2><SPAN class=150565113-07092001>an take 
</SPAN></FONT><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>either of two routes:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>1) Install activeScripting by running a file within the 
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>&nbsp;&nbsp;&nbsp;winall package. This allows you to 
write .pys WSH </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>&nbsp;&nbsp; scripts and run them using wscript.exe or 
cscript.exe</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>2) Just use winall's native COM facilities to create 
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>&nbsp;&nbsp;&nbsp;the WSH COM objects - this seems to 
be Mark Hamonds </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>&nbsp;&nbsp;&nbsp;personal favourite 
method.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>Using method&nbsp;1 and stealing an example from Marks 
Win32 </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>book we get the following example:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>######## wshtest.pys #######</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>WScript.Echo('The script is: ',WScript.SciptName) # Use 
WSH natively</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>if len(WScript.Arguments):</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>&nbsp;&nbsp; wshell = 
WScript.CreateObject("WScript.Shell")</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>&nbsp;&nbsp; wshell.Run("notepad.exe " + 
WScript.Arguments(0))</SPAN></FONT></DIV></SPAN></FONT><FONT color=#0000ff 
face="Courier New" size=2><SPAN 
class=150565113-07092001>else:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>&nbsp;&nbsp; WScript.Echo('No arguments 
passed')</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>############################</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>Run it by entering </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>C:\&gt; cscript wshtest.pys&nbsp; foo bar 
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>at a DOS prompt or</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>C:\&gt; wscript wshtest.pys baz</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>to get GUI style messages</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>Doing the same in native Python requires&nbsp;a mix of 
WSH </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>and raw Python:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>######## wshtest.py ########</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>from win32com.client import 
Dispatch</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>import sys</SPAN></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>print 'The script is: ',sys.argv[0]</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001><BR>if len(sys.argv) &gt; 1:<BR>&nbsp;&nbsp; wshell = 
Dispatch("WScript.Shell")<BR>&nbsp;&nbsp; wshell.Run("notepad.exe 
"+sys.argv[1])<BR>else:<BR>&nbsp;&nbsp; print 'No arguments 
passed'<BR></SPAN></FONT></DIV></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>############################</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>HTH,</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=150565113-07092001>Alan g</SPAN></FONT></DIV><FONT color=#0000ff 
face="Zurich BT" size=1>
<P 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">&nbsp;</P></FONT></BODY></HTML>

------_=_NextPart_001_01C137A9.1367B950--