[Python.NET] Dynamic types of returns PyObject from the runtime

Pierre-Yves Strub pierre-yves at strub.nu
Mon Jan 28 17:05:44 CET 2013


Hi,

While playing with the .NET python runtime (see code bellow), I have 
been surprised to see that the dynamic type of all values returned by 
the runtime is PyObject. For instance, in the latter example, I would 
expect "sum" to be of dynamic type PyInt and to be able to write (sum 
:?> PyInt) instead of (PyInt.AsInt sum). Is it a "feature" of the 
runtime binding ?

let entry () =
     PythonEngine.Initialize ()
     use lock    = new PythonEngineLock () in
     use builtin = PythonEngine.ImportModule ("__builtin__") in
     use data    =
         new PyList
             (data |> Array.map (fun i -> new PyInt (i) :> PyObject)) in
     use sum     = builtin.GetAttr("sum").Invoke([|data :> PyObject|]) in

         printfn "%A" (sum.GetType ());
         printfn "%A" (sum.GetPythonType ())


Best,
     Pierre-Yves.


More information about the PythonDotNet mailing list