[python-win32] win32com array handling bug?

Mark Hammond mhammond at skippinet.com.au
Thu Jul 5 01:12:33 CEST 2007


> I'm making a COM call that should return a two dimensional
> array, but
> instead I get back a buffer that appears to only contain a
> single row
> from the array.
>
> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
> (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import win32com.client
>  >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib")
>  >>> cams=mi.OpenCameras("C:\Program Files\Micron
> Imaging\sensor_data")
>  >>> c=cams[0]
>  >>> c.startTransport()
>  >>> c.updateFrameSize(c.sensor.width, c.sensor.height, 8,0)
>  >>> f=c.grabFrame()
>
> At this point f should be a 2048 by 1536 array of bytes, but
> instead...
>
>  >>> len(f)
> 2048
>  >>> type(f)
> <type 'buffer'>

Arrays of type VT_UI1 are returned as buffers.  You should find the length
of f is 1536, and you can treat it as a string (ie, just index into it to
fetch the values, len() to get the length, slice it, etc).  This is
primarily done as an optimization, so we don't need to waste time and space
building lists of lists of integers when the data is more naturally a
'string of bytes' anyway.

Mark



More information about the Python-win32 mailing list