passing dictionaries through COM

Steve Holden sholden at holdenweb.com
Fri Jan 11 07:34:30 EST 2002


"Ken Guest" <kwg at renre-europe.com> wrote ...
> hi,
> Does anybody know if it is possible to return a dictionary through COM
> to a VB application?
> I have tried a simple return {1: "a", 2: "b"} from my python code and
> get an error raised "Unexpected Python Error: exceptions.TypeError:
> Objects of type 'dictionary' can not be converted to a COM VARIANT' and
> was wondering if there is any 'deep magic'/advanced method of
> transferring a dictionary of information to a COM based client.
>
You need to wrap Python objects inside a COM interface before they can be
used in VB and other MS/COM environments. Your'e in luck:

"""
As you can see, the DynamicPolicy has given you the tools to wrap any
arbitrary Python object, rather than requiring you to explicitly declare the
public interface. Depending on your requirements, this may or may not serve
your purpose better than the default policy, but if neither of these
policies meet your requirements, just write your own! The Python.Dictionary
sample COM object (implemented in the module win32com.servers.dictionary)
implements its own specialized policy, so it's a good starting point if you
need to go this route.
"""

>From Hammond and Robinson's "Programming Python on Win32", Chapter 12, which
is fortuitously used as an online sample at

    http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list