My question is similar to this one but I got a slightly different scenario and actual code, I need to call a function giving it 2 params, one of them an array of objects (as seen in the example python2 file code) and receive the output, also an array of objects (not showed in this example code for simplification purposes).
My python2 file:
#!/usr/bin/env python
from subprocess import call
if __name__ == "__main__":
pathToFile = '/home/scripts/'
arr = [{'x': 1, 'y': 2, 'z': 3}, {'x': 2, 'y': 2, 'z': 2}]
output = call([pathToFile + 'python3', 3, arr])
My python3 file:
#!/usr/bin/env python3
import numpy as np
import sys
def python3Function(poses,kernelCount):
#complex calculations using py3 functionalities hidden for minified example
x = 3
y = 5
z = np.atleast_1d(x) @ np.atleast_1d(y)
return z
if __name__ == "__main__":
kernelCount= sys.argv[1]
poses= sys.argv[2]
print(python3Function(poses,kernelCount))
Currently it seems the call method only takes in strings because I get following error:
TypeError: execv() arg 2 must contain only strings
Importing the method directly also doesn't work because it uses python specific syntax like @
and results in the error:
SyntaxError: invalid syntax
The answer from the linked question gives me two options, I quote:
- Talk over a pipe or socket
- Enable such python 3 features as you can from
__future__
or use a library like six to write code which is compatible with both.
I have absolutely no idea what that guy is talking about and which of these 3 methods I should use in my case...I need actual code for my example, the simpler the better, then I will understand.