[python-win32] OLE COM in Python

Mark Hammond mhammond at skippinet.com.au
Wed May 25 01:44:48 CEST 2011


[Re-added pywin32 - please keep replies there]

On 25/05/2011 9:39 AM, kycbusiness at kycbusiness.com wrote:
> Dear Dr. Hammond,
>
> Thank you again.
>
> What I have tried to do is to transmit data from Python
> to Matlab, using COM OLE. Here is my code:
>
>>>> ml=win32com.client.Dispatch("Matlab.Application")
>>>> N=3
>>>> ml.Execute("M=N")
> u"??? Undefined function or variable 'N'.\n\n"

I don't know matlab at all, but I expect you want that second line to say:

ml.Execute("N=3")

All you have done in your version is set a Python variable named 'N' to 
3, not a matlab variable - so matlab is returning a string indicating 
the error.  Python and matlab don't magically share a namespace via COM.

HTH,

Mark

>
>>>> ml.Execute("C=magic(3)")
> u'\nC =\n\n     8     1     6\n     3     5     7\n     4     9     2\n\n'
>
> I can only input the integer 3 explicitly inside "Execute()", but not
> from Python.
>
> You are the world's authority in COM, your help will be very much appreciated.
>
> Sincerely,
>
> Kin Cheung
>
>
>
>
> ----- Original Message -----
> From: kycbusiness at kycbusiness.com
> To: mhammond at skippinet.com.au
> Cc: kycbusiness at kycbusiness.com
> Sent: Monday, May 23, 2011 9:34:02 PM
> Subject: Re: [python-win32] OLE COM in Python
>
> Dear Dr. Hammond,
>
> Thank you very much for your instruction.
>
> Sincerely,
>
> Kin Cheung
>
>
>
> ----- Original Message -----
> From: "Mark Hammond"<skippy.hammond at gmail.com>
> To: kycbusiness at kycbusiness.com
> Cc: python-win32 at python.org
> Sent: Monday, May 23, 2011 8:47:14 PM
> Subject: Re: [python-win32] OLE COM in Python
>
> On 23/05/2011 7:59 PM, kycbusiness at kycbusiness.com wrote:
>> Dear sir,
>>
>> I am looking for a sample python script to declare VARIANTs
>> similar to one shown below which is for Perl. Your help will be very
>> much appreciated.
>
> win32com doesn't have a way to explicitly declare variants - you just
> pass normal Python objects (eg, simple objects like ints or floats, or
> lists of them) and they are converted to variants internally.
>
> HTH,
>
> Mark



More information about the python-win32 mailing list