Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Execute Python Code in QM Using python.net
#9
I added a static function named pyCall to the Pynet class. It works very well when testing the example code in LA, but it doesn't work in QM.

string code = """
def Multi(a1, a2):
    return a1 * a2
""";
var a = Pynet.pyCall(code, "Multi", 6, 7);
print.it(a);
 
Code:
Copy      Help
public static object pyCall(string code, string func = null, params object[] args)
{

    using (var pyn = new Pynet(code))
    {

        dynamic m = pyn.Module;
        var pyFunc = m.GetAttr(func);

        PyObject[] pyArgs = args.Select(arg => arg.ToPython()).ToArray();
        using (var result = pyFunc.Invoke(pyArgs))
        {

            return result.AsManagedObject(typeof(object));
        }
    }
}


qm code: 
Code:
Copy      Help
ARRAY(VARIANT) args.create
sel getopt(nargs)-1
,case 1 args[]=_A1
,case 2 args[]=_A1; args[]=_A2
,case 3 args[]=_A1; args[]=_A2; args[]=_A3
,case 4 args[]=_A1; args[]=_A2; args[]=_A3; args[]=_A4
,case 5 args[]=_A1; args[]=_A2; args[]=_A3; args[]=_A4; args[]=_A5
ret x.Call("Pynet.pyCall" code _Func args)

QM Err info:
0x80004002, Interface not supported.
The specified conversion is invalid.


Messages In This Thread
RE: First steps with Python.NET - by Davider - 06-09-2025, 03:30 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)