Salome HOME
5af75272d67da83f7af4da3b2c3fbfb1fb6e1847
[tools/medcoupling.git] / doc / user / doxygen / doxfiles / start / python-api.dox
1 /*!
2
3 \page python-api A word on the Python API
4
5 The Python API is highly similar to the C++ one. The main modules to import are:
6 - <B>%MEDCoupling</B>
7 - <B>%MEDLoader</B> (with mainly the static \ref MEDLoader "MEDLoader class" within this module)
8
9 The following intuitive rules have been used to map the C++ objects to the Python ones:
10 - std::vector become standard Python lists, see for example \ref py_mcdataarrayint_setpartofvalues where the function
11 ParaMEDMEM::DataArray::setInfoOnComponents() is used.
12 - the return values of C++ functions (usually passed as last arguments in the C++ prototype) are
13 returned directly as a tuple, see for example the Python usage of ParaMEDMEM::MEDCouplingUMesh::getReverseNodalConnectivity() in \ref cpp_mcumesh_getReverseNodalConnectivity. The 
14 initial prototype where the return values are passed as argument can however still be used, provided you instantiate
15 the returned objects first.
16 - the indexing mechanism is greatly simplified in Python, and offers similar functionalities to what NumPy 
17 provides thanks to the ':' (column) operator. Once can for example refer to part of an array with something like
18  
19 \code{.py}
20 import MEDCoupling as mc
21 d = mc.DataArrayInt([(1,2), (3,4), (5,6)], 3, 2)   # an array of 3 tuples with 2 components
22 print d[:,1]                                       # show only second component of the array: 2,4,6
23 \endcode
24  
25
26 Finally for the most common objects (DataArray, MEDCouplingUMesh, etc ...) one can direclty access the
27 Doxygen documentation in the interactive Python interpreter using the built-in help function from Python:
28
29 \code{.py}
30 import MEDCoupling as mc
31 help(mc.DataArrayDouble.getNumberOfTuples)
32 \endcode
33
34
35 */