How to Call Methods from Python

Once you have created an object, you call methods on it using normal Python method calls. The arguments to the method only include the in and inout arguments, and the return value of the Python method includes the SIDL return value and the inout and out parameters. Hopefully, this will seem natural to Python programmers. For the following example, the object obj has a method passeverywhere with the following SIDL declaration:


double passeverywhere( in double d1, out double d2, inout double d3 );

You can see the Python calling signature with print obj.passeverywhere.__doc__. Here is what that shows for this example:


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

In the method documentation, the SIDL method's return value is called _return; and unless the method is void, the return value always appears first. The fact that _return 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 /** */ comments) appear below the Babel generated signature documentation.

Static methods of a class are available in the Python x.y.z namespace assuming you use the import x.y.z command. Static methods have documentation just like class methods.

Examples of calls to SIDL overloaded methods are based on the overload_sample.sidl file shown in Section 5.6. Recall that the file describes three versions of the getValue 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:


  b1 = 1
  i1 = 1

  t = Overload.Sample.Sample()
  
  nresult = t.getValue()
  iresult = t.getValueInt(i1) 
  bresult = t.getValueBool(b1)



babel-0.10.2
users_guide Last Modified 2005-03-23

http://www.llnl.gov/CASC/components
components@llnl.gov