Arguments of function as out

B

Birgit Rahm

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
 
?

=?ISO-8859-1?Q?Gerhard_H=E4ring?=

Birgit said:
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
 
P

Piet van Oostrum

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

Birgit Rahm

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
 
A

Alex Martelli

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

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
 
B

Birgit Rahm

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

Jeff Epler

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
 
A

Alex Martelli

Birgit Rahm wrote:

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

Perfect, thanks!

I dont understood this in the you described it.

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
 
D

Duncan Grisby

Birgit Rahm said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top