# Python equivalent of C++ pass by reference

**URL:** <https://discourse.slicer.org/t/python-equivalent-of-c-pass-by-reference/15710>\
**Category:** Support\
**Tags:** python\
**Created:** [January 28, 2021, 10:10am UTC](https://discourse.slicer.org/t/python-equivalent-of-c-pass-by-reference/15710 "2021-01-28T10:10:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joachim](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@joachim](https://discourse.slicer.org/u/joachim)\
**Post date:** [January 28, 2021, 10:10am UTC](https://discourse.slicer.org/t/python-equivalent-of-c-pass-by-reference/15710/1 "2021-01-28T10:10:51Z")

</div>

Here is an example of a C++ function using pass by reference (non-const pointer arguments): [vtkMRMLAnnotationsROINode::GetXYZ(double[3] point)](http://apidocs.slicer.org/master/classvtkMRMLAnnotationROINode.html#a951f54fefa1e4e9e8a0f0ec7439e96f7).

How do I call this function in Python, i.e. pass an array as argument? With no arguments, `node.GetXYZ()` gives _TypeError: GetXYZ() takes exactly 1 argument (0 given)_.

---

<div class="post-metadata">

**Author:** ![Andinet\_Enquobahrie](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/andinet_enquobahrie/32/75_2.png) [@Andinet\_Enquobahrie](https://discourse.slicer.org/u/Andinet_Enquobahrie)\
**Post date:** [January 28, 2021, 1:22pm UTC](https://discourse.slicer.org/t/python-equivalent-of-c-pass-by-reference/15710/2 "2021-01-28T13:22:23Z")

</div>

Dear @joachim

you have to first create a list array. For example.

```python
# create annotation ROI MRML node 

roi = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLAnnotationROINode")

# interact with it in the application.. move it around then to retrieve the center of the annotation ROI

point = [0., 0., 0.]
roi.GetXYZ(point)

```

HTH  
Andinet

---

<div class="post-metadata">

**Author:** ![joachim](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@joachim](https://discourse.slicer.org/u/joachim)\
**Post date:** [January 30, 2021, 2:50pm UTC](https://discourse.slicer.org/t/python-equivalent-of-c-pass-by-reference/15710/3 "2021-01-30T14:50:10Z")

</div>

Thank you, this was very helpful for me! It should be some tip for this on the wiki - how to emulate C++ calls through Python - because the [C++ API](http://apidocs.slicer.org/master/index.html) is the only way I know how to do Python scripting.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 30, 2021, 3:40pm UTC](https://discourse.slicer.org/t/python-equivalent-of-c-pass-by-reference/15710/4 "2021-01-30T15:40:53Z")

</div>

> [@joachim](#):
>
> It should be some tip for this on the wiki - how to emulate C++ calls through Python - because the [C++ API](http://apidocs.slicer.org/master/index.html) is the only way I know how to do Python scripting

This page describes how to translate C++ API to Python: [Slicer API — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/api.html#doxygen-style-documentation)

Some additional useful tips: [Python FAQ — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/python_faq.html)
