1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 2002-2-1 (1.70)
original version by: Nikos Drakos, CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>How to Call Methods from Python</TITLE>
<META NAME="description" CONTENT="How to Call Methods from Python">
<META NAME="keywords" CONTENT="users_guide">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="users_guide.css">
<LINK REL="next" HREF="node166.html">
<LINK REL="previous" HREF="node164.html">
<LINK REL="up" HREF="node162.html">
<LINK REL="next" HREF="node166.html">
</HEAD>
<BODY >
<DIV CLASS="navigation"><!--Navigation Panel-->
<A NAME="tex2html3171"
HREF="node166.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html3165"
HREF="node162.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html3159"
HREF="node164.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<A NAME="tex2html3167"
HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
<A NAME="tex2html3169"
HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html3172"
HREF="node166.html">Catching and Throwing Exceptions</A>
<B> Up:</B> <A NAME="tex2html3166"
HREF="node162.html">Python Bindings</A>
<B> Previous:</B> <A NAME="tex2html3160"
HREF="node164.html">How to Cast SIDL</A>
<B> <A NAME="tex2html3168"
HREF="node14.html">Contents</A></B>
<B> <A NAME="tex2html3170"
HREF="node317.html">Index</A></B>
<BR>
<BR></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION03630000000000000000"></A>
<A NAME="10153"></A>
<BR>
How to Call Methods from Python
</H1>
<P>
Once you have created an object, you call methods on it using normal
Python method calls. The arguments to the method only include the
<A NAME="10154"></A><TT>in</TT> and <TT>inout</TT> arguments, and the return value of the
Python method includes the SIDL return value and the <TT>inout</TT> and
<TT>out</TT> parameters. Hopefully, this will seem natural to Python
programmers. For the following example, the object <TT>obj</TT> has a
method <TT>passeverywhere</TT> with the following SIDL declaration:
<P>
<BR>
<PRE CLASS="verbatim">double passeverywhere( in double d1, out double d2, inout double d3 );
</I></PRE></td></tr></table></blockquote>
<P>
You can see the Python calling signature with <TT><B>print
obj.passeverywhere.__doc__</B></TT>. Here is what that shows for this
example:
<P>
<BR>
<PRE CLASS="verbatim">$ python
>>> import Args.Cdouble
>>> obj = Args.Cdouble.Cdouble()
>>> print obj.passeverywhere.__doc__
passeverywhere(in double d1,
inout double d3)
RETURNS
(double _return,
out double d2,
inout double d3)
</PRE></td></tr></table></blockquote>
<P>
In the method documentation, the SIDL method's return value is called
<TT>_return</TT>; and unless the method is <TT>void</TT>, the return
value always appears first. The fact that <TT>_return</TT> starts with
an underbar should alert you to the fact that it is not a parameter
because parameter names cannot start with an underbar. The document
comments from the SIDL file (i.e. comments enclosed in <TT>/** */</TT>
comments) appear below the Babel generated signature documentation.
<P>
Static methods of a class are available in the Python <TT>x.y.z</TT>
namespace assuming you use the <TT><B>import x.y.z</B></TT> command. Static
methods have documentation just like class methods.
<P>
Examples of calls to SIDL overloaded methods are based on the
<TT>overload_sample.sidl</TT> file shown in Section <A HREF="node107.html#sec:overloading">5.6</A>.
Recall that the file describes three versions of the <TT>getValue</TT> method.
The first takes no arguments, the second takes an integer argument, and the
third takes a boolean. Each is called in the code snippet below:
<P>
<BR>
<PRE CLASS="verbatim">
b1 = 1
i1 = 1
t = Overload.Sample.Sample()
nresult = t.getValue()
iresult = t.getValueInt(i1)
bresult = t.getValueBool(b1)
</PRE></td></tr></table></blockquote>
<P>
<DIV CLASS="navigation"><HR>
<!--Navigation Panel-->
<A NAME="tex2html3171"
HREF="node166.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html3165"
HREF="node162.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html3159"
HREF="node164.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<A NAME="tex2html3167"
HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
<A NAME="tex2html3169"
HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html3172"
HREF="node166.html">Catching and Throwing Exceptions</A>
<B> Up:</B> <A NAME="tex2html3166"
HREF="node162.html">Python Bindings</A>
<B> Previous:</B> <A NAME="tex2html3160"
HREF="node164.html">How to Cast SIDL</A>
<B> <A NAME="tex2html3168"
HREF="node14.html">Contents</A></B>
<B> <A NAME="tex2html3170"
HREF="node317.html">Index</A></B> </DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<br><br>babel-0.10.2<br>users_guide Last Modified 2005-03-23<br><br><a href="http://www.llnl.gov/CASC/components">http://www.llnl.gov/CASC/components</a><br><a href="mailto:components@llnl.gov">components@llnl.gov</a>
</ADDRESS>
</BODY>
</HTML>
|