# Python console warnings for deprecated methods

**URL:** <https://discourse.slicer.org/t/python-console-warnings-for-deprecated-methods/6218>\
**Category:** Development\
**Created:** [March 20, 2019, 5:56pm UTC](https://discourse.slicer.org/t/python-console-warnings-for-deprecated-methods/6218 "2019-03-20T17:56:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [March 20, 2019, 5:56pm UTC](https://discourse.slicer.org/t/python-console-warnings-for-deprecated-methods/6218/1 "2019-03-20T17:56:17Z")

</div>

I was debugging a code that iterated over segmentation nodes as below

```python
sn = slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLSegmentationNode')
while sn:
  ...
  sn = slicer.mrmlScene.GetNextNodeByClass('vtkMRMLSegmentationNode')

```

and it was getting only the first node from the scene.

I then searched for the method in the source code, and found that the method I was using was deprecated: [https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkMRMLScene.h#L246-L253](https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkMRMLScene.h#L246-L253)

There is even a `vtkWarningMacro()` in the implementation of that method: [https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkMRMLScene.cxx#L1655](https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkMRMLScene.cxx#L1655), but nothing gets printed out on the console to warn the user when that method is used (at least not for me).

Is that warning supposed to be printed? Is it a bug, or some setting that prevented me from seeing it?

---

<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:** [March 20, 2019, 7:06pm UTC](https://discourse.slicer.org/t/python-console-warnings-for-deprecated-methods/6218/2 "2019-03-20T19:06:37Z")

</div>

You can use [getNodesByClass](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.getNodesByClass) method to get all nodes of a certain class in a Python list.

`slicer.mrmlScene.GetNextNodeByClass()` failed for you because traversing the MRML node list is initialized by `slicer.mrmlScene.InitTraversal()` method call (and not `GetFirstNodeByClass`). We kept the method for only backward compatibility. Documentation of how to use it was removed because it could have encouraged people to use it.

VTK errors are not printed on the Python console. It is not a bug, but I agree that it could be a useful feature to have. We would probably not want to flood the console with log VTK messages all the time, so I’m not sure what the expected behavior would be.

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [March 20, 2019, 7:13pm UTC](https://discourse.slicer.org/t/python-console-warnings-for-deprecated-methods/6218/3 "2019-03-20T19:13:51Z")

</div>

Thanks Andras. I was able to quickly fix the code once I realized that method was deprecated.
