· Feb 17 2m read

Returning values with python

Why am I writting this?

Last year I made an article for starters on using embedded python. Later, it started a little discussion on how to return values with python and I found some interesting observations that are worth writing a little article. Also, hopefully I can reach more people by writing this.


Possible situations

There are two things you'll need to care about when returning a value with python. The first is the type you're trying to return and the second is where you're returning it. 

Let's remember our first lessons when we started coding: in python, when you define a function you can end it by writing "return" followed by the value, if any. In IRIS, to end a method or class method you do the same, otherwise using the key word "quit". Here you're gonna do the exact same thing. Whenever you want to return a value you'll simply write "return" followed by the value.

So what is the problem? None. You just have to be careful if you need some type validation, since, if you're using python in IRIS, the value will be treated as IRIS treats values (which is pretty "problemless" I think), and if your using IRIS in python, python will interpret your value as it understands. 



Return a value in a method written in Python, in IRIS environment:

Class python.returnTest [ Abstract ]

ClassMethod returnSomething(pValue As %String) As %String [ Language = python ]
	return pValue


notice how python interprets as if it is in a definition of a function that will later be called.


Return a value in python environment using iris package:

the "print()" function in the end is just to show the results on the console.

In the same way you could create a function in python and use it's return value in IRIS environment, etc. I believe that past now, it is not worth showing endless examples, but to discuss how those values will be interpreted. 



For common types such as integers, decimals, booleans and strings it is easy to understand and to work with (although booleans may differ from program to program). But for types such as python/IRIS lists and arrays, you might want to study a little more - you have to understand how to properly use the iris module and the %SYS.Python class, which I'll discuss in the next article.


Thank you for reading and I hope this was helpful.
Feel free to contact me if you need any help.

Discussion (0)1
Log in or sign up to continue