[python-win32] Executing eval function in VBscript

Mark Hammond mhammond at skippinet.com.au
Tue Feb 5 07:18:22 CET 2008

You probably want to take a copy of interp.py and modify it so that when a
dictionary is returned, you return something like the Python.Dictionary
object (see win32com\servers\dictionary.py).  You can create such an object
via something like:


>>> from win32com.servers.dictionary import DictionaryPolicy

>>> from win32com.server.util import wrap

>>> ob = wrap({"foo":"bar"}, usePolicy=DictionaryPolicy)

>>> ob

<PyIDispatch at 0x01507A88 with obj at 0x01511620>


If interp.py returned 'ob', VB should be able to access it somewhat like a
regular VB collection - so instead of simply:


        return eval(str(exp), self.dict)


you checked the result, and if it's a dict, execute the lines above and
return 'ob' instead of the dict (and obviously using a real dict instead of
the constant one in the example above)


Hope this helps (and works ;)




From: python-win32-bounces at python.org
[mailto:python-win32-bounces at python.org] On Behalf Of Janakiraman
Sent: Tuesday, 5 February 2008 4:48 PM
To: cappy2112 at gmail.com
Cc: bgailer at alum.rpi.edu; python-win32 at python.org
Subject: Re: [python-win32] Executing eval function in VBscript


yes i want to have python functionality in excel, 
iam trying to call python functions from VBscript, 
more like evaluating a python expression say dictionary or list in VBscript 
For evaluating a python expression , python has some library functions like
eval which takes python expressions 
 in string format and checks whether it is a valid python expression or not 

so i thought of calling that python eval function in VBscript and validate
my datas 
but the problem is when i tried to pass dictionaries for eg, "{'key':value}"
this is the format of dictionary in python 
VBscript throws error like type mismatch 
since VB dictionary representation of VB and python are different 

Thanks and Regards!

"Tony Cappellini" <cappy2112 at gmail.com> 

02/05/2008 01:51 AM 

Please respond to
cappy2112 at gmail.com


python-win32 at python.org 


bgailer at alum.rpi.edu, janakiraman.mohanakrishnan at tcs.com 


[python-win32] Executing eval function in VBscript



Date: Mon, 04 Feb 2008 10:05:11 -0500
From: bob gailer <bgailer at alum.rpi.edu>
Subject: Re: [python-win32] Executing eval function in VBscript
To: Janakiraman Mohanakrishnan <janakiraman.mohanakrishnan at tcs.com>
Cc: python-win32 at python.org
Message-ID: <47A729A7.5030709 at alum.rpi.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

>>That's hard to answer until we know what you want to accomplish! Tell us
>>more. What problem are you trying to solve?

I think he wants to have python functionality from excel, which is
what I'd like to accomplish as well.
(Python embedded into excel, as opposed to launching Excel from Python)

>>Also I'm not very familiar with MSScriptControl. I googled it and found
>>no useful documentation. Do you have any references to it?
Everything you want to know about the MSScriptControl is on microsoft's


Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20080205/f2063acb/attachment-0001.htm 

More information about the python-win32 mailing list