[Info-vax] Python integration examples
Arne Vajhøj
arne at vajhoej.dk
Tue Dec 15 20:44:29 EST 2020
On 12/15/2020 8:48 AM, Marc Van Dyck wrote:
> Apparently it is possible to write code so that a set of routines
> present in a shareable image can be called from within a Python program.
> Could someone shed some light, provide examples, any sort of guidance,
> about how I can actually achieve this ?
Obviously there are the docs. But sometimes a bit extra
info helps.
I have written a little example:
Python code:
https://wwww.vajhoej.dk/arne/articles/call2.html#py_ctypes
C code & VMS build:
https://www.vajhoej.dk/arne/articles/call2.html#common
One change to the Python code for VMS:
DISK2:[ARNE.py]pydemolib.py;1
cdll.LoadLibrary('stddemolib') ## cdll.LoadLibrary('stddemolib.dll')
(that one should be pretty obvious)
And if your VMS Python does not have numpy module (my 2.7 does not)
the sum function does not work so:
DISK2:[ARNE.py]pydemolib.py;1
##from numpy import *
##demolib.std_sum.argtypes = [c_int, ctypeslib.ndpointer(dtype=int32)]
##demolib.std_sum.restype = c_int
##def sum(a):
## return demolib.std_sum(len(a), array(a))
DISK2:[ARNE.py]TestPy.py;1
##six = [1, 2, 3, 4, 5, 6]
##allsix = pydemolib.sum(six)
##print(allsix)
Arne
More information about the Info-vax
mailing list