3 \page python-api A word on the Python API
5 The Python API is highly similar to the C++ one. The main modules to import are:
7 - <B>%MEDLoader</B> (with mainly the static \ref MEDLoader "MEDLoader class" within this module)
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
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
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:
30 import MEDCoupling as mc
31 help(mc.DataArrayDouble.getNumberOfTuples)