Skip to main content

hi,

when I use PyCallMethod or PyCallFunction, the result is typed by python.

uvPythons doc talk about PYOBJECT.

so, how can we define if pyCall return a PYOBJECT or a string/number usable in basic ? 

Actually, I perform a pyCallMethod(builtins,'str',myvariable) 

Is there a better method ? 

manythanks.



------------------------------
Manu Fernandes
------------------------------

hi,

when I use PyCallMethod or PyCallFunction, the result is typed by python.

uvPythons doc talk about PYOBJECT.

so, how can we define if pyCall return a PYOBJECT or a string/number usable in basic ? 

Actually, I perform a pyCallMethod(builtins,'str',myvariable) 

Is there a better method ? 

manythanks.



------------------------------
Manu Fernandes
------------------------------

Manu,

That would work but there are some objects that may throw an exception , so you would have to handle that in your code as well.

There are also cases where the string returned may not be what you want in the variable.

For example, Python uses he NoneType object to define Null objects and variables, yet it will return the word None, if you convert it to a string. 

>>> noneTypeExample = None
>>> help(noneTypeExample)
Help on NoneType object:

class NoneType(object)
 |  Methods defined here:
 |
 |  __bool__(self, /)
 |      True if self else False
 |
 |  __repr__(self, /)
 |      Return repr(self).
 |
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.

>>> str(noneTypeExample)
'None'
>>>

Another way you might want to check is Python 'type' function, and based on what it returns, take the proper action or set the variable accordingly.   

Note that for Python modules I am writing, I like to make sure I return a number or a string.  If I am not returning a number or a string, I only use object in subsequent calls to other Python functions and/or methods which may return  a string or number.



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------

Manu,

That would work but there are some objects that may throw an exception , so you would have to handle that in your code as well.

There are also cases where the string returned may not be what you want in the variable.

For example, Python uses he NoneType object to define Null objects and variables, yet it will return the word None, if you convert it to a string. 

>>> noneTypeExample = None
>>> help(noneTypeExample)
Help on NoneType object:

class NoneType(object)
 |  Methods defined here:
 |
 |  __bool__(self, /)
 |      True if self else False
 |
 |  __repr__(self, /)
 |      Return repr(self).
 |
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.

>>> str(noneTypeExample)
'None'
>>>

Another way you might want to check is Python 'type' function, and based on what it returns, take the proper action or set the variable accordingly.   

Note that for Python modules I am writing, I like to make sure I return a number or a string.  If I am not returning a number or a string, I only use object in subsequent calls to other Python functions and/or methods which may return  a string or number.



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------

Hi Mike

Thank you for the response. 

Yes builtin type() is a method too. 

May I suggest you add a uv basic function to do it ? Like we have for filevar aka. Fileinfo(var, x) , we can have pyinfo()var,x)  to check the complete 'python' info of the variable (is-ok-in-basic,nature(numeric, text, boolean, sequence ( list,  tuple,  range), set, dictionary)) , class_name),...) 

Yes, I can write it myself.. 

Regarding, 'write py to be sure to return string or number, okay, but for little action it can be usefull to consume py modules without encapsulate it into a wrapper and stringize/numberize everthing. 

I have the same request about UDO variable... Then why not create a varinfo(var, x) to return if x=0  the basic type (string, number, null, filevar, pyobject, udo).

Just a suggest 

With kind regards 



------------------------------
Manu Fernandes
------------------------------

Hi Mike

Thank you for the response. 

Yes builtin type() is a method too. 

May I suggest you add a uv basic function to do it ? Like we have for filevar aka. Fileinfo(var, x) , we can have pyinfo()var,x)  to check the complete 'python' info of the variable (is-ok-in-basic,nature(numeric, text, boolean, sequence ( list,  tuple,  range), set, dictionary)) , class_name),...) 

Yes, I can write it myself.. 

Regarding, 'write py to be sure to return string or number, okay, but for little action it can be usefull to consume py modules without encapsulate it into a wrapper and stringize/numberize everthing. 

I have the same request about UDO variable... Then why not create a varinfo(var, x) to return if x=0  the basic type (string, number, null, filevar, pyobject, udo).

Just a suggest 

With kind regards 



------------------------------
Manu Fernandes
------------------------------

Manu,

We do have an open enhancement request for this and I will add you to the request.  

I did also find that we can determine if it is a Python Object with the DESCRINFO function. 

i.e.: pymodule = PyImport(ModuleName)
         CRT "descrinfo: ":DESCRINFO(1, pymodule)

If a Python object is stored in the variable checked, the DESCRINFO is returning -1



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------

Manu,

We do have an open enhancement request for this and I will add you to the request.  

I did also find that we can determine if it is a Python Object with the DESCRINFO function. 

i.e.: pymodule = PyImport(ModuleName)
         CRT "descrinfo: ":DESCRINFO(1, pymodule)

If a Python object is stored in the variable checked, the DESCRINFO is returning -1



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------

Hi Mike,

DESCRINFO(key,var) ... yes, add PYOBJECT and UDO to the returned type.... and enhance the key capabilities for more information. 

Good idea. 

Thank you to put me on that loop.

With kind regards



------------------------------
Manu Fernandes
------------------------------

Hi Mike,

DESCRINFO(key,var) ... yes, add PYOBJECT and UDO to the returned type.... and enhance the key capabilities for more information. 

Good idea. 

Thank you to put me on that loop.

With kind regards



------------------------------
Manu Fernandes
------------------------------

Manu,

I am not sure I would rely on the DESCRINFO returning a -1 result because Universe also returns -1 when the variable is a list variable.

       EXECUTE 'SELECT VOC SAMPLE' RTNLIST X CAPTURING DUMMY
       CRT 'DESCRINFO( 1, X ): ' : DESCRINFO( 1, X )



------------------------------
Joseph von Arx
Software Developer
Data Management Associates Inc DMA
Cincinnati OH US
------------------------------

Hi Mike,

DESCRINFO(key,var) ... yes, add PYOBJECT and UDO to the returned type.... and enhance the key capabilities for more information. 

Good idea. 

Thank you to put me on that loop.

With kind regards



------------------------------
Manu Fernandes
------------------------------

Manu,

Exactly, and also XDOM.  While this will not remove the need to dig deeper if there is a Python Object returned, it will be a better way to check after a python call.



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------