# Way to print for both perspective and vision projects?

**URL:** <https://forum.inductiveautomation.com/t/way-to-print-for-both-perspective-and-vision-projects/34793>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [May 15, 2020, 5:33pm UTC](https://forum.inductiveautomation.com/t/way-to-print-for-both-perspective-and-vision-projects/34793 "2020-05-15T17:33:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 15, 2020, 5:33pm UTC](https://forum.inductiveautomation.com/t/way-to-print-for-both-perspective-and-vision-projects/34793/1 "2020-05-15T17:33:29Z")

</div>

I have a Ignition project that has both a vision and perspective aspect to them. They share some business logic functions. I would like it if I could craft a print function that would handle printing if it was in vision or perspective, given one I have to use `print` and the other I have to use `system.perspective.print`. Has anyone figured out a way to do this?

Basically I want something like

```auto
def print(message, ???):
    if ???:
        print message
    else:
        system.perspective.print(message)

```

but I can’t think of a way for this print function to “know” if things are being called from perspective or vision, except for passing some parameter, which I would then have to include for every single function that wants to print. Any ideas how I can figure out the scope of what is calling what function so that I can print regardless?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 15, 2020, 6:00pm UTC](https://forum.inductiveautomation.com/t/way-to-print-for-both-perspective-and-vision-projects/34793/2 "2020-05-15T18:00:14Z")

</div>

```python
from __future__ import print_function
import __builtin__
from java.lang import IllegalArgumentException 

def print(*objects, **kwargs):
	sep = kwargs.pop("sep", ", ")
	end = kwargs.pop("end", "\n")
	message = sep.join(str(object) for object in objects)
	try:
		system.perspective.print(message)
	except IllegalArgumentException:
		system.util.getLogger("utils.print").info(message)
	except AttributeError:
		__builtin__.print(message, end=end) 

```

Dropped in a `utils` script module. I would definitely recommend _not_ naming a function `print` (notice the `from __future__ ` import that was required), but it’s technically possible.

It’ll try to use system.perspective.print; if that fails due to the `IllegalArgumentException` (meaning you’re on the gateway, but not inside Perspective) then it’ll bail out to a logging statement. But, if `system.perspective` is an `AttributeError`, meaning you’re not on the gateway at all, it just uses the builtin `print` function.

Note that performance on the non-happy path is going to be dramatically worse than the native `print` statement; throwing and catching exceptions is expensive. There’s probably a better way to only run the same logic once; @pturmel may have some ideas, but this works to at least prove the concept.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 15, 2020, 7:19pm UTC](https://forum.inductiveautomation.com/t/way-to-print-for-both-perspective-and-vision-projects/34793/3 "2020-05-15T19:19:05Z")

</div>

Would checking for the existence of a client-scoped tag work?

```python
def universalPrint(message):
    if system.tag.exists('[System]Client/User/Username'):
        print message
    else:
        system.perspective.print(message)

```
