Products Resources Support About Us

Quandry regarding u2py.Dynarray


#1

From the XDEMO account in UniVerse 11.3.1 running on Red Hat Enterprise Linux Server release 7.4, after starting Python and importing u2py, getting the following…

Welcome to the XDEMO Account
Version: 3.1.0

WHO
1 XDEMO From daveh-aws
PYTHON
python> import u2py
python> help(u2py.Dynarray)
Traceback (most recent call last):
File “”, line 1, in
AttributeError: ‘module’ object has no attribute ‘Dynarray’

Not sure what to do. Help requested. Thanks,

Dave Howell

P.S. the to_list() works with my Windows UVPE.


#2

Try ‘help(u2py.DynArray)’ — the case of the object matters


#3

Michael, thanks for pointing out the typo – forest and trees sometimes huh? So, “help(u2py.DynArray)” worked. Now, I find a problem with its to_list() method…

I have a ‘driver’ basic program that calls a ‘pytest.py’ module with a ‘test_call’ function. The driver and python module are as follows:

driver

module_name = “pytest”
function_name = ‘test_call’

x = “TEMP”
x<2> = "daveh@marketamerica.com"
x<3> = “3363237692”
print 'passing in x value: ':x
pyresult = PyCallFunction(module_name, function_name, x)
IF @PYEXCEPTIONTYPE = “” THEN
CRT “py call successfull”
END ELSE
CRT "EXCEPTION TYPE IS " :@PYEXCEPTIONTYPE
CRT "EXCEPTION MESSAGE IS " :@PYEXCEPTIONMSG
CRT "EXCEPTIONTRACEBACK IS " :@PYEXCEPTIONTRACEBACK
END

pytest.py

import u2py
def test_call(i_list):
    print('In pytest: received i_list:' + i_list)
    print('converting i_list to a python list')
    pylist = u2py.DynArray(i_list).to_list()
    print('pylist: {}'.format(pylist))
    print('pylist length is: {}'.format(len(pylist)))
    print('pylist type is: {}'.format(type(pylist)))

Output

02 run util.uvs driver
passing in x value: TEMP▒daveh@marketamerica.com▒3363237692
In pytest: received i_list:TEMP�daveh@marketamerica.com�3363237692
converting i_list to a python list
pylist: [‘TEMP�daveh@marketamerica.com�3363237692’]
pylist length is: 1
pylist type is: <class ‘list’>
py call successfull

Beside the delimiter marks that don’t copy well from a terminal session, you will notice that the to_list() function is not splitting the i_list dynamic array as evidenced by the length being 1 and the value of pylist is still a single dynamic array string.

I’m probably doing something stupid again, but for the life of me I can’t see what.

Thanks,

Dave

P.S. The to_list() method works with my Windows UVPE.


#4

Interesting, I think I see the issue. What is you encoding.

Note easiest way to tell is
import sys
help(sys)

it is at the bottom


#5

Note while I am still looking into this to determine how this occurs, it seems, like I mentioned in my previous post, that the encoding is off. I found that in some cases when python can not determine the encoding, it defaults to ANSI_X3.4-1968.

Good thing is that you can workaround this issue by setting the environment variable

PYTHONIOENCODING=“iso-8859-1”
export PYTHONIOENCODING

Note in my testing, I stopped and started the database with the parameter set, as well as having it set for the user.


#6

Ok. So, I set the environment variables as directed for both the database and user as evidenced by the ‘env’ cli output:

SSH_CLIENT=10.99.140.27 61821 22
SELINUX_USE_CURRENT_RANGE=
SSH_TTY=/dev/pts/0
PYTHONIOENCODING=“iso-8859-1”
USER=daveh-aws

Running the driver program produces the following:

run util.uvs driver
passing in x value: TEMP▒daveh@marketamerica.com▒3363237692
EXCEPTION TYPE IS UnicodeEncodeError
EXCEPTION MESSAGE IS ‘latin-1’ codec can’t encode character ‘\ufffd’ in position 31: ordinal not in range(256)
EXCEPTIONTRACEBACK IS Traceback (most recent call last):

File “/uvfs/ma.accounts/dvh/pymodules/pytest.py”, line 5, in test_call
print(‘In pytest: received i_list:’ + i_list)

UnicodeEncodeError: ‘latin-1’ codec can’t encode character ‘\ufffd’ in position 31: ordinal not in range(256)

I also realized that I neglected to inform that NLS is enabled on the Linux install, but not on my UVPE. Might that have something to do with it?

I also saw in the “U2 Python User Guide” the following reference:

the u2py module, a property config.encoding is added, the value of which is set
by default to the current operating system’s input and output encoding. In most cases, the property
will work as intended, but it is also programmatically changeable. So if the property does not match
the native encoding the U2 engine is using and causes issues for the Python applications, the Python
application developer can always change it.

I would try to change the config.encoding, but don’t know how and possible what to change it to.

Thanks again.


#7

Created a case, and will work with you and Engineering on this issue. Once I have an answer, I will come back an update this forum post.


#8

Very well sir. Thanks for your help.


#9

Michael, still no luck with the environment variable setting. However, I haven’t had much to troubleshoot further – other priorities taking precedence; one of which is getting python-kafka to work with UV Basic, which have have been successful with. We are passing parameters between UV programs and Python functions using json instead of dynamic arrays. This more approximates the way our web services work. That being said. At some point I intend to return to troubleshooting this issue. IPlease do what you must with the open case. If need be I can open another. Was the engineering fix put in place?