Interoperability between VB and Python under ASP
paulpaterson at users.sourceforge.net
Thu Sep 4 04:20:56 CEST 2003
> Max Ischenko <max at ucmg.com.ua> wrote in message news:<bj46f2$kk2$1 at voodoo.volia.net>...
>>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.
> http://vb2py.sourceforge.net/ 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 = """
if x = 0 then
factorial = 1
factorial = x*factorial(x-1)
from vb2py.vbparser import parseVB, VBCodeModule
"""Translate VBScript fragment to Python"""
block = parseVB(match.groups(), 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 *
if x == 0:
_ret = 1
_ret = x * factorial(x - 1)
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.
vb2py :: A Visual Basic to Python Conversion Toolkit
More information about the Python-list