# Clear Python Interactor pogrammatically

**URL:** <https://discourse.slicer.org/t/clear-python-interactor-pogrammatically/7773>\
**Category:** Development\
**Created:** [July 26, 2019, 3:50pm UTC](https://discourse.slicer.org/t/clear-python-interactor-pogrammatically/7773 "2019-07-26T15:50:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manuel](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Manuel](https://discourse.slicer.org/u/Manuel)\
**Post date:** [July 26, 2019, 3:50pm UTC](https://discourse.slicer.org/t/clear-python-interactor-pogrammatically/7773/1 "2019-07-26T15:50:52Z")

</div>

Is there any posibility to clear the Python Interactor pogrammatically within a loable module?

Thanks in advanced.  
Manuel

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [July 26, 2019, 4:21pm UTC](https://discourse.slicer.org/t/clear-python-interactor-pogrammatically/7773/2 "2019-07-26T16:21:47Z")

</div>

Just curious, can you provide more information about why you want to clear the python interactor? There might be a better solution to the problem that you are trying to solve.

---

<div class="post-metadata">

**Author:** ![Manuel](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Manuel](https://discourse.slicer.org/u/Manuel)\
**Post date:** [July 26, 2019, 4:29pm UTC](https://discourse.slicer.org/t/clear-python-interactor-pogrammatically/7773/3 "2019-07-26T16:29:40Z")

</div>

In my module, I have some logging infos during the process and at the start of the algorithm within the module, I want to clear the Python Interactor (the resulting logging infos) from the run before.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [July 26, 2019, 7:03pm UTC](https://discourse.slicer.org/t/clear-python-interactor-pogrammatically/7773/4 "2019-07-26T19:03:54Z")

</div>

You could use the function `ctkPythonConsole::clear()`

From python, the following can be done:

```python
slicer.app.pythonConsole().clear()

```

From a C++ loadable module, you would have to do something like this:

```cpp
#include "qSlicerApplication.h"

// CTK includes
#include <ctkPythonConsole.h>

[...]

qSlicerApplication* app = qSlicerApplication::application();
app->pythonConsole()->clear();

```

---

<div class="post-metadata">

**Author:** ![Manuel](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Manuel](https://discourse.slicer.org/u/Manuel)\
**Post date:** [July 26, 2019, 7:27pm UTC](https://discourse.slicer.org/t/clear-python-interactor-pogrammatically/7773/5 "2019-07-26T19:27:38Z")

</div>

> [@jcfr](#):
>
> slicer.app.pythonConsole().clear()

Yes! Thats exactly what I need. Thank you so much Jean!
