Arguments of function as out

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Birgit Rahm

    Arguments of function as out


    Hallo Newsgroup,

    I have the following problem:
    I work with Python 2.2 and invoke functions via CORBA ( I use
    onmiORB/omniORBpy) on a server.
    The server provides me a function, where the 3 arguments are out-arguments
    and the return is void / None.
    How can I get these out arguments?
    I have read that every argument is seen as local to the function and can not
    be used as return value.
    (I can't redesign the server function.)
    Can I make the 3 arguments global before they were used in the function?
    Does this help me?
    Or what can I do?

    TIA, Birgit



  • Piet van Oostrum

    #2
    Re: Arguments of function as out

    >>>>> "Birgit Rahm" <br_y@yahoo.d e> (BR) wrote:

    BR> Hallo Newsgroup,

    BR> I have the following problem:
    BR> I work with Python 2.2 and invoke functions via CORBA ( I use
    BR> onmiORB/omniORBpy) on a server.
    BR> The server provides me a function, where the 3 arguments are out-arguments
    BR> and the return is void / None.
    BR> How can I get these out arguments?
    BR> I have read that every argument is seen as local to the function and
    BR> can not be used as return value.
    BR> (I can't redesign the server function.)
    BR> Can I make the 3 arguments global before they were used in the function?
    BR> Does this help me?
    BR> Or what can I do?

    This is described in the Python language binding:

    Operations of an interface map to methods available on the object references.
    Parameters with a parameter attribute of in or inout are passed from left to
    right to the method, skipping out parameters. The return value of a method
    depends on the number of out parameters and the return type. If the
    operation returns a value, this value forms the first result value. All
    inout or out parameters form consecutive result values. The method result
    depends then on the number of result values:

    * If there is no result value, the method returns None.
    * If there is exactly one result value, it is returned as a single value.
    * If there is more than one result value, all of them are packed into a
    tuple, and this tuple is returned.
    --
    Piet van Oostrum <piet@cs.uu.n l>
    URL: http://www.cs.uu.nl/~piet [PGP]
    Private email: P.van.Oostrum@h ccnet.nl

    Comment

    • Birgit Rahm

      #3
      Re: Arguments of function as out


      Thank you,
      I've already read this, but I hoped, there is a way to get these out
      parameters beside this.
      Because I cant redesign the function on the server side. So I have only the
      possibility to change the client side code, which calls this function.
      It seems there is no way in python to use it and get the new out paramter
      value after finishing the function.
      Birgit


      "Piet van Oostrum" <piet@cs.uu.n l> schrieb im Newsbeitrag
      news:wzoey20yy4 .fsf@nono.cs.uu .nl...[color=blue][color=green][color=darkred]
      > >>>>> "Birgit Rahm" <br_y@yahoo.d e> (BR) wrote:[/color][/color]
      >
      > BR> Hallo Newsgroup,
      >
      > BR> I have the following problem:
      > BR> I work with Python 2.2 and invoke functions via CORBA ( I use
      > BR> onmiORB/omniORBpy) on a server.
      > BR> The server provides me a function, where the 3 arguments are[/color]
      out-arguments[color=blue]
      > BR> and the return is void / None.
      > BR> How can I get these out arguments?
      > BR> I have read that every argument is seen as local to the function and
      > BR> can not be used as return value.
      > BR> (I can't redesign the server function.)
      > BR> Can I make the 3 arguments global before they were used in the[/color]
      function?[color=blue]
      > BR> Does this help me?
      > BR> Or what can I do?
      >
      > This is described in the Python language binding:
      >
      > Operations of an interface map to methods available on the object[/color]
      references.[color=blue]
      > Parameters with a parameter attribute of in or inout are passed from left[/color]
      to[color=blue]
      > right to the method, skipping out parameters. The return value of a method
      > depends on the number of out parameters and the return type. If the
      > operation returns a value, this value forms the first result value. All
      > inout or out parameters form consecutive result values. The method result
      > depends then on the number of result values:
      >
      > * If there is no result value, the method returns None.
      > * If there is exactly one result value, it is returned as a single value.
      > * If there is more than one result value, all of them are packed into a
      > tuple, and this tuple is returned.
      > --
      > Piet van Oostrum <piet@cs.uu.n l>
      > URL: http://www.cs.uu.nl/~piet [PGP]
      > Private email: P.van.Oostrum@h ccnet.nl[/color]


      Comment

      • Alex Martelli

        #4
        Re: Arguments of function as out

        Birgit Rahm wrote:
        [color=blue]
        > Thank you,
        > I've already read this, but I hoped, there is a way to get these out
        > parameters beside this.
        > Because I cant redesign the function on the server side. So I have only
        > the possibility to change the client side code, which calls this function.
        > It seems there is no way in python to use it and get the new out paramter
        > value after finishing the function.[/color]

        Birgit, you do not seem to have *READ* the answer to which you are
        replying. Let me quote it again (since you violate netiquette by
        this "top-post", putting your response before the text you are
        responding to):
        [color=blue][color=green]
        >> All inout or out parameters form consecutive result values. The method
        >> result depends then on the number of result values:
        >>
        >> * If there is no result value, the method returns None.
        >> * If there is exactly one result value, it is returned as a single value.
        >> * If there is more than one result value, all of them are packed into a
        >> tuple, and this tuple is returned.[/color][/color]

        Read it again, *CAREFULLY*. Nothing here requires you to "redesign
        the function on the server side": it's only, STRICTLY about what you
        do in "the client side code, which calls this function", as you say.

        For example: you say you have a function, say X, which has three
        arguments, all 'out' parameters, and returns void. Very well then,
        according to the Python language binding which Piet quoted to you,
        from the point of view of the Python client code calling X, X is
        returning a tuple which packs the three result values!

        So, you call it as:

        a, b, c = X()

        and that's all! Note you do NOT pass arguments corresponding to
        out parameters (you DO pass arguments corresponding to in and inout
        parameters, if any); you get result values corresponding to the
        function's nonvoid return if any (none here) followed by all out
        and inout parameters.

        It ain't all that hard, really...


        Alex

        Comment

        • Birgit Rahm

          #5
          Re: Arguments of function as out


          Hallo Alex,
          I hope this posting is near to the netiquette.
          [color=blue]
          > Birgit, you do not seem to have *READ* the answer to which you are
          > replying.[/color]
          I dont understood this in the you described it.
          [color=blue][color=green][color=darkred]
          > >> * If there is more than one result value, all of them are packed into a
          > >> tuple, and this tuple is returned.[/color][/color][/color]
          I've read this, but I thought that this tuple is returned with the
          return statement. I am new to python and I never seen such
          a constract:
          [color=blue]
          > Very well then,
          > according to the Python language binding which Piet quoted to you,
          > from the point of view of the Python client code calling X, X is
          > returning a tuple which packs the three result values!
          >
          > So, you call it as:
          >
          > a, b, c = X()
          >
          > and that's all! Note you do NOT pass arguments corresponding to
          > out parameters (you DO pass arguments corresponding to in and inout
          > parameters, if any); you get result values corresponding to the
          > function's nonvoid return if any (none here) followed by all out
          > and inout parameters.[/color]

          I have had only the IDL and the py File from the IDL,
          were stand take *args and return the return value.
          In none of my python books such a construct is described. I'm sorry.

          Thanks for helping me,
          Birgit


          Comment

          • Alex Martelli

            #6
            Re: Arguments of function as out

            Birgit Rahm wrote:

            [color=blue]
            > Hallo Alex,
            > I hope this posting is near to the netiquette.[/color]

            Perfect, thanks!

            [color=blue][color=green]
            >> Birgit, you do not seem to have *READ* the answer to which you are
            >> replying.[/color]
            > I dont understood this in the you described it.
            >[color=green][color=darkred]
            >> >> * If there is more than one result value, all of them are packed into
            >> >> a
            >> >> tuple, and this tuple is returned.[/color][/color]
            > I've read this, but I thought that this tuple is returned with the
            > return statement. I am new to python and I never seen such
            > a constract:[/color]

            The code that implements this CORBA spec (if it is Python code -- it
            is quite possible to implement CORBA brokers in Python, and it has
            been done) will quite likely use the return statement for this, yes,
            of course. But when you CALL the code, you don't need to worry
            whether it uses a return statement or some other black magic: you
            can code your call AS IF the code you called was Python code that
            uses a return statement for the tuple, e.g.

            def X():
            return 23, 42, 69

            therefore you call it as, e.g.:

            a, b, c = X()

            would set a to 23, b to 42, c to 69. (You need to know how many
            items are in the tuple X returns, to use this kind of assigment
            which is called "unpacking assignment", because you need to list
            exactly that number of targets on the left of the = sign).

            [color=blue]
            > I have had only the IDL and the py File from the IDL,
            > were stand take *args and return the return value.
            > In none of my python books such a construct is described. I'm sorry.
            >
            > Thanks for helping me,[/color]

            No problem, and you're welcome. I do understand that Python books
            don't say much about Corba (I didn't myself in the Nutshell, and
            there is just one very simple example in the Cookbook which does
            not cover the cases of out and inout parameters). But if the books
            don't cover *args and/or return-value packing and unpacking, then
            you might want to get better books;-)


            Alex

            Comment

            • Duncan Grisby

              #7
              Re: Arguments of function as out

              In article <bj6l5v$3qg$06$ 1@news.t-online.com>,
              Birgit Rahm <br_y@yahoo.d e> wrote:
              [color=blue]
              >I've already read this, but I hoped, there is a way to get these out
              >parameters beside this.[/color]

              Aside from all the help Alex has already given you, perhaps you should
              have read the very next part of the specification, after the bit Piet
              quoted. It says:

              """
              Assuming the IDL definition

              interface I {
              oneway void stop();
              bool more_data();
              void get_data(out string name, out long age);
              };

              a client could write

              names = {}
              while my_I.more_data( ):
              name,age = my_I.get_data()
              names[name] = age
              my_I.stop()
              """

              I don't think it can get much clearer than that.

              Cheers,

              Duncan.

              --
              -- Duncan Grisby --
              -- duncan@grisby.o rg --
              -- http://www.grisby.org --

              Comment

              • Jeff Epler

                #8
                Re: Arguments of function as out

                On Thu, Sep 04, 2003 at 08:12:57AM +0200, Birgit Rahm wrote:[color=blue]
                >
                > Thank you,
                > I've already read this, but I hoped, there is a way to get these out
                > parameters beside this.
                > Because I cant redesign the function on the server side. So I have only the
                > possibility to change the client side code, which calls this function.
                > It seems there is no way in python to use it and get the new out paramter
                > value after finishing the function.
                > Birgit[/color]

                I found this result when searching for 'omniorbpy "out parameter"':

                I don't know for certain that this is the way omniorbpy behaves today,
                but it is a very pythonic way to work.

                | From: Duncan Grisby <dgrisby at uk dot research dot att dot com>
                | Subject: [omniORB] omniORBpy out parameter passing issue
                |
                [...]
                | Out arguments in the Python mapping appear as extra return values in a
                | tuple. So, if you have IDL
                |
                | interface I {
                | long op(in string a, out short b, inout double c);
                | };
                |
                | Then to call op, you do
                |
                | (result, b, c) = i.op(a, c)
                |
                | I recommend that you read the mapping specification, which you can
                | download from
                |
                | http://www.omg.org/cgi-bin/doc?ptc/00-01-12
                |
                | Cheers,
                |
                | Duncan.

                Jeff

                Comment

                • Gerhard Häring

                  #9
                  Re: Arguments of function as out

                  Birgit Rahm wrote:[color=blue]
                  > Hallo Newsgroup,[/color]

                  Hi Birgit,
                  [color=blue]
                  > I have the following problem:
                  > I work with Python 2.2 and invoke functions via CORBA ( I use
                  > onmiORB/omniORBpy) on a server.
                  > The server provides me a function, where the 3 arguments are out-arguments
                  > and the return is void / None.
                  > How can I get these out arguments? [...][/color]

                  The out (or inout) parameters will be returned as return parameters of
                  the method. In your case there should be a 3-tuple of the out parameters
                  returned.

                  See the Python-IDL Language Mapping for details (search for "out
                  parameter" in this document):



                  -- Gerhard

                  Comment

                  Working...