Interoperability between VB and Python under ASP

Paul Paterson paulpaterson at
Thu Sep 4 04:20:56 CEST 2003

bigdog wrote:
> Max Ischenko <max at> wrote in message news:<bj46f2$kk2$1 at>...
>>I've started to develop under Microsoft ASP framework, which allows 
>>different lang. used in a ActiveX page. I wonder about possible 
>>strategies to use Python modules from VBScript <%%> includes.
> I don't know if this will help, but it might be worth a shot.
> I've never used it myself, I only point
> it out as a curiosity I've heard of

Although it isn't (currently) targetted at VBScript, the CVS version of 
vb2py might help if you have reasonably sized blocks of VBScript code to 
convert. It hasn't been tested on VBScipt specifically but the parser 
should work for most things and I'd certainly be interested to hear of 
any specific problems with ASP scripts.

Out of the box it won't even recognize code in a .asp page, but I threw 
together the following code. I'm not an expert on ASP or VBScript but 
even if this is not correct it might point you in the right direction if 
you want to try a convert-to-python route ....

test = """

function factorial(x)
if x = 0 then
     factorial = 1
     factorial = x*factorial(x-1)
end if
end function


from vb2py.vbparser import parseVB, VBCodeModule
import re

def translateScript(match):
     """Translate VBScript fragment to Python"""
     block = parseVB(match.groups()[0], container=VBCodeModule())
     return "<%%\n%s\n%%>" % block.renderAsCode()

converter = re.compile(r"\<%(.*?)%\>", re.DOTALL + re.MULTILINE)
print converter.sub(translateScript, test)

... which should output:

from vb2py.vbfunctions import *

def factorial(x):
     if x == 0:
         _ret = 1
         _ret = x * factorial(x - 1)
     return _ret


You'll need the CVS version to get this to work - the v0.1.1 doesn't 
have the full parser and the v0.2 release is a couple of weeks off yet.

If you do decide to try this route, I'd be very interested to hear of 
any specific issues that come up with translating ASP/VBScript to Python.


Paul Paterson

vb2py :: A Visual Basic to Python Conversion Toolkit

More information about the Python-list mailing list