Arguments of function as out

Discussion in 'Python' started by Birgit Rahm, Sep 3, 2003.

  1. Birgit Rahm

    Birgit Rahm Guest

    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
     
    Birgit Rahm, Sep 3, 2003
    #1
    1. Advertising

  2. Birgit Rahm wrote:
    > Hallo Newsgroup,


    Hi Birgit,

    > 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? [...]


    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):

    http://www.python.org/wiki/pub/CorbaPython/attachments/01-02-66.pdf

    -- Gerhard
     
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Sep 3, 2003
    #2
    1. Advertising

  3. >>>>> "Birgit Rahm" <> (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 <>
    URL: http://www.cs.uu.nl/~piet [PGP]
    Private email:
     
    Piet van Oostrum, Sep 3, 2003
    #3
  4. Birgit Rahm

    Birgit Rahm Guest

    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" <> schrieb im Newsbeitrag
    news:...
    > >>>>> "Birgit Rahm" <> (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 <>
    > URL: http://www.cs.uu.nl/~piet [PGP]
    > Private email:
     
    Birgit Rahm, Sep 4, 2003
    #4
  5. Birgit Rahm wrote:

    > 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, 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):

    >> 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.


    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
     
    Alex Martelli, Sep 4, 2003
    #5
  6. Birgit Rahm

    Birgit Rahm Guest

    Hallo Alex,
    I hope this posting is near to the netiquette.

    > Birgit, you do not seem to have *READ* the answer to which you are
    > replying.

    I dont understood this in the you described it.

    > >> * If there is more than one result value, all of them are packed into a
    > >> tuple, and this tuple is returned.

    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:

    > 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.


    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
     
    Birgit Rahm, Sep 4, 2003
    #6
  7. Birgit Rahm

    Jeff Epler Guest

    On Thu, Sep 04, 2003 at 08:12:57AM +0200, Birgit Rahm wrote:
    >
    > 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


    I found this result when searching for 'omniorbpy "out parameter"':
    http://www.omniorb-support.com/pipermail/omniorb-list/2000-April/015244.html
    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
     
    Jeff Epler, Sep 4, 2003
    #7
  8. Birgit Rahm wrote:


    > Hallo Alex,
    > I hope this posting is near to the netiquette.


    Perfect, thanks!


    >> Birgit, you do not seem to have *READ* the answer to which you are
    >> replying.

    > I dont understood this in the you described it.
    >
    >> >> * If there is more than one result value, all of them are packed into
    >> >> a
    >> >> tuple, and this tuple is returned.

    > 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:


    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).


    > 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,


    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
     
    Alex Martelli, Sep 4, 2003
    #8
  9. In article <bj6l5v$3qg$06$-online.com>,
    Birgit Rahm <> wrote:

    >I've already read this, but I hoped, there is a way to get these out
    >parameters beside this.


    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 --
    -- --
    -- http://www.grisby.org --
     
    Duncan Grisby, Sep 4, 2003
    #9
    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. Neo
    Replies:
    10
    Views:
    683
    sushant
    Jan 20, 2005
  2. tutmann
    Replies:
    4
    Views:
    449
  3. jmborr
    Replies:
    1
    Views:
    435
    Stargaming
    Nov 3, 2007
  4. Replies:
    3
    Views:
    842
  5. Navaneeth
    Replies:
    4
    Views:
    559
    Kenny McCormack
    Nov 20, 2010
Loading...

Share This Page