passing an array of variant in vb to a python COM object = win32com bug ?

Discussion in 'Python' started by vml, May 3, 2007.

  1. vml

    vml Guest

    I have a python com object which contains a method to inverse an array
    in vb 6 the definition of the class is :

    class Fop:
    _public_methods_ = [ 'SqVal' ]
    def SqVal(self,*val):
    #vol=(val[0][0],val[0][1])
    #mat1=mat((vol))
    #up=linalg.inv(mat1)
    return str(val)#up
    _reg_verprogid_ = "Python.Fop.3"
    _reg_progid_ = "Python.Fop"
    _reg_desc_ = "Python Fop"
    _reg_clsid_ = "{30BD3490-2632-11cf-AD5B-524153480001}"

    I pass to this method an array of variant which is the matrix to
    invert like that:
    vb6 code :


    Set obj = CreateObject("Python.Fop")
    Dim ty(1, 1) As Variant

    ty(0, 0) = 1
    ty(1, 0) = 2
    ty(0, 1) = 3
    ty(1, 1) = 4

    toto = obj.SqVal(ty)


    when I dispaly toto as str(val) I obtain the following tuple "(((1,
    3), (2, 4)),)" which is not usable ....

    Do you have an idea to explain this strange behaviour ?

    thank you !
     
    vml, May 3, 2007
    #1
    1. Advertising

  2. En Thu, 03 May 2007 04:54:43 -0300, vml <> escribió:

    > I have a python com object which contains a method to inverse an array
    > in vb 6 the definition of the class is :
    >
    > class Fop:
    > _public_methods_ = [ 'SqVal' ]
    > def SqVal(self,*val):
    > #vol=(val[0][0],val[0][1])
    > #mat1=mat((vol))
    > #up=linalg.inv(mat1)
    > return str(val)#up
    > _reg_verprogid_ = "Python.Fop.3"
    > _reg_progid_ = "Python.Fop"
    > _reg_desc_ = "Python Fop"
    > _reg_clsid_ = "{30BD3490-2632-11cf-AD5B-524153480001}"
    >
    > I pass to this method an array of variant which is the matrix to
    > invert like that:
    > vb6 code :
    >
    >
    > Set obj = CreateObject("Python.Fop")
    > Dim ty(1, 1) As Variant
    >
    > ty(0, 0) = 1
    > ty(1, 0) = 2
    > ty(0, 1) = 3
    > ty(1, 1) = 4
    >
    > toto = obj.SqVal(ty)
    >
    >
    > when I dispaly toto as str(val) I obtain the following tuple "(((1,
    > 3), (2, 4)),)" which is not usable ....
    >
    > Do you have an idea to explain this strange behaviour ?


    This is the expected behaviour. Writing it completely in Python:

    py> def SqVal(*val):
    .... return str(val)
    ....
    py> ty=((1,3),(2,4))
    py> SqVal(ty)
    '(((1, 3), (2, 4)),)'

    The *val parameter receives a tuple, whose elements are the positional
    arguments used when calling the function. As you call the function with a
    single argument, val receives a tuple with a single element.
    Perhaps you want to write it as:

    py> def SqVal(val):
    .... print val[0][0]
    .... print val[0][1]
    .... print val[1][0]
    .... print val[1][1]
    ....
    py> SqVal(ty)
    1
    3
    2
    4

    (Of course, if used as a Fop method, dont forget the "self" parameter)

    --
    Gabriel Genellina
     
    Gabriel Genellina, May 3, 2007
    #2
    1. Advertising

  3. vml

    vml Guest

    On 3 mai, 14:20, "Gabriel Genellina" <> wrote:
    > En Thu, 03 May 2007 04:54:43 -0300, vml <> escribió:
    >
    >
    >
    > > I have a python com object which contains a method to inverse an array
    > > in vb 6 the definition of the class is :

    >
    > > class Fop:
    > > _public_methods_ = [ 'SqVal' ]
    > > def SqVal(self,*val):
    > > #vol=(val[0][0],val[0][1])
    > > #mat1=mat((vol))
    > > #up=linalg.inv(mat1)
    > > return str(val)#up
    > > _reg_verprogid_ = "Python.Fop.3"
    > > _reg_progid_ = "Python.Fop"
    > > _reg_desc_ = "Python Fop"
    > > _reg_clsid_ = "{30BD3490-2632-11cf-AD5B-524153480001}"

    >
    > > I pass to this method an array of variant which is the matrix to
    > > invert like that:
    > > vb6 code :

    >
    > > Set obj = CreateObject("Python.Fop")
    > > Dim ty(1, 1) As Variant

    >
    > > ty(0, 0) = 1
    > > ty(1, 0) = 2
    > > ty(0, 1) = 3
    > > ty(1, 1) = 4

    >
    > > toto = obj.SqVal(ty)

    >
    > > when I dispaly toto as str(val) I obtain the following tuple "(((1,
    > > 3), (2, 4)),)" which is not usable ....

    >
    > > Do you have an idea to explain this strange behaviour ?

    >
    > This is the expected behaviour. Writing it completely in Python:
    >
    > py> def SqVal(*val):
    > ... return str(val)
    > ...
    > py> ty=((1,3),(2,4))
    > py> SqVal(ty)
    > '(((1, 3), (2, 4)),)'
    >
    > The *val parameter receives a tuple, whose elements are the positional
    > arguments used when calling the function. As you call the function with a
    > single argument, val receives a tuple with a single element.
    > Perhaps you want to write it as:
    >
    > py> def SqVal(val):
    > ... print val[0][0]
    > ... print val[0][1]
    > ... print val[1][0]
    > ... print val[1][1]
    > ...
    > py> SqVal(ty)
    > 1
    > 3
    > 2
    > 4
    >
    > (Of course, if used as a Fop method, dont forget the "self" parameter)
    >
    > --
    > Gabriel Genellina


    I just tried to replace the *val by SqVal(self,val) and call the
    method in vb but it crashes down :

    "when refilling safe array the sequence must have the same number of
    dimension as the existing array"

    my python code is now :

    def SqVal(self,val):
    ## volr=[val[0][0] for i in range(size(val,2))]
    ## voli=[val[0][1] for i in range(size(val,2))]
    ## mat1=mat(volr)+1j*mat(voli)
    ## up=linalg.pinv(mat1)
    ## out=up.real.tolist()
    ## out.extend(up.imag.tolist())
    return val

    By the way Do you have any idea to debug the com server script ? ( I
    would like to know if a can access the value in the function while
    calling it from vb 6)




    tahnks a lot !
     
    vml, May 3, 2007
    #3
  4. vml

    Larry Bates Guest

    Re: passing an array of variant in vb to a python COM object = win32combug ?

    vml wrote:
    > On 3 mai, 14:20, "Gabriel Genellina" <> wrote:
    >> En Thu, 03 May 2007 04:54:43 -0300, vml <> escribió:
    >>
    >>
    >>
    >>> I have a python com object which contains a method to inverse an array
    >>> in vb 6 the definition of the class is :
    >>> class Fop:
    >>> _public_methods_ = [ 'SqVal' ]
    >>> def SqVal(self,*val):
    >>> #vol=(val[0][0],val[0][1])
    >>> #mat1=mat((vol))
    >>> #up=linalg.inv(mat1)
    >>> return str(val)#up
    >>> _reg_verprogid_ = "Python.Fop.3"
    >>> _reg_progid_ = "Python.Fop"
    >>> _reg_desc_ = "Python Fop"
    >>> _reg_clsid_ = "{30BD3490-2632-11cf-AD5B-524153480001}"
    >>> I pass to this method an array of variant which is the matrix to
    >>> invert like that:
    >>> vb6 code :
    >>> Set obj = CreateObject("Python.Fop")
    >>> Dim ty(1, 1) As Variant
    >>> ty(0, 0) = 1
    >>> ty(1, 0) = 2
    >>> ty(0, 1) = 3
    >>> ty(1, 1) = 4
    >>> toto = obj.SqVal(ty)
    >>> when I dispaly toto as str(val) I obtain the following tuple "(((1,
    >>> 3), (2, 4)),)" which is not usable ....
    >>> Do you have an idea to explain this strange behaviour ?

    >> This is the expected behaviour. Writing it completely in Python:
    >>
    >> py> def SqVal(*val):
    >> ... return str(val)
    >> ...
    >> py> ty=((1,3),(2,4))
    >> py> SqVal(ty)
    >> '(((1, 3), (2, 4)),)'
    >>
    >> The *val parameter receives a tuple, whose elements are the positional
    >> arguments used when calling the function. As you call the function with a
    >> single argument, val receives a tuple with a single element.
    >> Perhaps you want to write it as:
    >>
    >> py> def SqVal(val):
    >> ... print val[0][0]
    >> ... print val[0][1]
    >> ... print val[1][0]
    >> ... print val[1][1]
    >> ...
    >> py> SqVal(ty)
    >> 1
    >> 3
    >> 2
    >> 4
    >>
    >> (Of course, if used as a Fop method, dont forget the "self" parameter)
    >>
    >> --
    >> Gabriel Genellina

    >
    > I just tried to replace the *val by SqVal(self,val) and call the
    > method in vb but it crashes down :
    >
    > "when refilling safe array the sequence must have the same number of
    > dimension as the existing array"
    >
    > my python code is now :
    >
    > def SqVal(self,val):
    > ## volr=[val[0][0] for i in range(size(val,2))]
    > ## voli=[val[0][1] for i in range(size(val,2))]
    > ## mat1=mat(volr)+1j*mat(voli)
    > ## up=linalg.pinv(mat1)
    > ## out=up.real.tolist()
    > ## out.extend(up.imag.tolist())
    > return val
    >
    > By the way Do you have any idea to debug the com server script ? ( I
    > would like to know if a can access the value in the function while
    > calling it from vb 6)
    >
    >
    >
    >
    > tahnks a lot !
    >
    >

    Debugging COM objects is best done using logging module or at least
    writing to a file during processing. You can review the log file
    to see what was going on.

    -Larry
     
    Larry Bates, May 3, 2007
    #4
  5. En Thu, 03 May 2007 09:41:57 -0300, vml <> escribió:
    > On 3 mai, 14:20, "Gabriel Genellina" <> wrote:
    >> En Thu, 03 May 2007 04:54:43 -0300, vml <>
    >> escribió:
    >>
    >> > I have a python com object which contains a method to inverse an array
    >> > in vb 6 the definition of the class is :

    >>

    > I just tried to replace the *val by SqVal(self,val) and call the
    > method in vb but it crashes down :
    >
    > "when refilling safe array the sequence must have the same number of
    > dimension as the existing array"


    That can't happen with your Python code below, so it must be on the
    caller. Maybe you wrote something like: xx=something.SqVal(yy) and xx,yy
    are declared of different sizes.

    > def SqVal(self,val):
    > ## ...
    > return val
    >
    > By the way Do you have any idea to debug the com server script ? ( I
    > would like to know if a can access the value in the function while
    > calling it from vb 6)


    Write a log file as suggested, or use OutputDebugString with the DebugView
    program from www.sysinternals.com

    --
    Gabriel Genellina
     
    Gabriel Genellina, May 4, 2007
    #5
  6. vml

    vml Guest

    On 4 mai, 06:56, "Gabriel Genellina" <> wrote:
    > En Thu, 03 May 2007 09:41:57 -0300,vml<> escribió:
    >
    > > On 3 mai, 14:20, "Gabriel Genellina" <> wrote:
    > >> En Thu, 03 May 2007 04:54:43 -0300,vml<>
    > >> escribió:

    >
    > >> > I have a python com object which contains a method to inverse an array
    > >> > in vb 6 the definition of the class is :

    >
    > > I just tried to replace the *val by SqVal(self,val) and call the
    > > method in vb but it crashes down :

    >
    > > "when refilling safe array the sequence must have the same number of
    > > dimension as the existing array"

    >
    > That can't happen with your Python code below, so it must be on the
    > caller. Maybe you wrote something like: xx=something.SqVal(yy) and xx,yy
    > are declared of different sizes.
    >


    It is true that I call the python routine like that in vb :


    toto = obj.SqVal(ty)

    If I am understanding well I need to pass an array of 2x2 and I should
    retireve an array of variant of 2x2 ....

    I tried to do that :
    vb6 :

    Dim obj As Object
    Dim toto(1, 1, 2) As Variant

    Set obj = CreateObject("Python.Fop")
    Dim ty(1, 1, 2) As Variant

    ty(0, 0, 0) = 1
    ty(0, 1, 0) = 2
    ty(0, 0, 1) = 3
    ty(0, 0, 2) = 7
    ty(0, 1, 1) = 4
    ty(0, 1, 2) = 45

    ty(1, 0, 0) = 1
    ty(1, 1, 0) = 2
    ty(1, 0, 1) = 3
    ty(1, 0, 2) = 7
    ty(1, 1, 1) = 4
    ty(1, 1, 2) = 45



    toto = obj.SqVal(ty)



    but it is saying that the compiler can not assign the array toto at
    the line toto=obj.SqVal().... hum strange .....



    any ideas ?


    Thank you for your help !






    > > def SqVal(self,val):
    > > ## ...
    > > return val

    >
    > > By the way Do you have any idea to debug the com server script ? ( I
    > > would like to know if a can access the value in the function while
    > > calling it from vb 6)

    >
    > Write a log file as suggested, or use OutputDebugString with the DebugView
    > program fromwww.sysinternals.com
    >
    > --
    > Gabriel Genellina
     
    vml, May 4, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,112
    Thomas 'PointedEars' Lahn
    Mar 20, 2006
  2. Vic
    Replies:
    1
    Views:
    928
    John Harrison
    Jul 10, 2003
  3. Demian
    Replies:
    1
    Views:
    1,410
    Victor Bazarov
    Nov 14, 2003
  4. Replies:
    9
    Views:
    596
    justanotherguy
    Dec 3, 2004
  5. Raoul
    Replies:
    2
    Views:
    745
    Raoul
    Jun 18, 2004
Loading...

Share This Page