Products Resources Support About Us

Rocket Software

PyCallFunction across accounts

When using the PyCallFunction in UniBasic I am able to call functions from modules I have built, but only from modules within the same account as the UniBasic code. Is it possible/How do I call a Python function across accounts?

To expand a bit, I have 2 accounts I am currently working with, A and B.

A has historically contained some of the larger Basic Programs that run my application. Many of these are globally catalogued and run from other accounts. I am trying to keep a similar structure in my python development.

Within account B I can write a Basic Program that runs pycallfunction on python programs within account B, but I am unable to call python programs outside of account B.

Is there an additional configuration step I need to feed UV? Or an additional parameter to feed PyCallFunction? Any suggestions would be super useful.

I have been asked that question before, and while The Rocket MultiValue databases deal with local and global catalog space you will need to decide on how you want to do something similar in Python.

If the Python module is in another account, and you want to import and use it, Python needs to know where to find it. The easy solution is to add the path to the other directory (in the other account) into a .pth file in the python directory.

Note that if you are using the Python that comes with the Rocket MultiValue Databases, it will have a u2.pth file.

i.e. on a windows system it would look something like:
C:\U2\ud82\bin
C:\U2\ud82\XDEMO\PP

So, in addition to the built ins and modules you loaded into python with pip, you would have access to the python code in the two paths listed above. ( the u2py module is in the U2 bin directory )

You could add the path to your other account in the u2.py, but it could be overwritten if you reinstall and/or upgrade U2. I recommend creating your own .pth file.

This would add the access to the other Python modules, but you could have issues if you have the same module name in two locations. The first one found would be used.

You can use the Python sys module to see the path, which shows what order the directories are searched.

i.e.

PYTHON
python> import sys
python> sys.path
[‘C:\U2\UV\python\python37.zip’, ‘C:\U2\UV\python\DLLs’, ‘C:\U2\UV\python\lib’, ‘C:\U2\UV\bin’, ‘C:\U2\UV\python’, ‘C:\U2\UV\XDEMO\PP’, ‘C:\U2\UV\python\lib\site-packages’]
python>

It is also possible to modify the sys.path. I would explain, but there are many sites dedicated to Python examples.

Mike Rajkowski