private void SetupStreams(ref ScriptRuntime runtime) { // set output stream PyObject sys = PythonEngine.ImportModule("sys"); sys.SetAttr("stdout", PyObject.FromManagedObject(runtime.OutputStream)); }
public PyObject TryEncode(object value) { if (value is null) { throw new ArgumentNullException(nameof(value)); } return(PyObject.FromManagedObject(value)); }
private void SetupCaching(ref ScriptRuntime runtime) { // set output stream PyObject sys = PythonEngine.ImportModule("sys"); // dont write bytecode (__pycache__) // https://docs.python.org/3.7/library/sys.html?highlight=pythondontwritebytecode#sys.dont_write_bytecode sys.SetAttr("dont_write_bytecode", PyObject.FromManagedObject(true)); }
public void RawListProxy() { var list = new List <string> { "hello", "world" }; var listProxy = PyObject.FromManagedObject(list); var clrObject = (CLRObject)ManagedType.GetManagedObject(listProxy.Handle); Assert.AreSame(list, clrObject.inst); }
public void RawPyObjectProxy() { var pyObject = "hello world!".ToPython(); var pyObjectProxy = PyObject.FromManagedObject(pyObject); var clrObject = (CLRObject)ManagedType.GetManagedObject(pyObjectProxy.Handle); Assert.AreSame(pyObject, clrObject.inst); var proxiedHandle = pyObjectProxy.GetAttr("Handle").As <IntPtr>(); Assert.AreEqual(pyObject.Handle, proxiedHandle); }
public void RawPyObjectProxy() { var pyObject = "hello world!".ToPython(); var pyObjectProxy = PyObject.FromManagedObject(pyObject); var clrObject = (CLRObject)ManagedType.GetManagedObject(pyObjectProxy); Assert.AreSame(pyObject, clrObject.inst); #pragma warning disable CS0612 // Type or member is obsolete const string handlePropertyName = nameof(PyObject.Handle); #pragma warning restore CS0612 // Type or member is obsolete var proxiedHandle = pyObjectProxy.GetAttr(handlePropertyName).As <IntPtr>(); Assert.AreEqual(pyObject.DangerousGetAddressOrNull(), proxiedHandle); }
public PyObject TryEncode(object value) => PyObject.FromManagedObject(this);
public PyObject TryEncode(object value) { // This is a no-op to prevent Python.NET from encoding generic lists // https://github.com/pythonnet/pythonnet/pull/963#issuecomment-642938541 return(PyObject.FromManagedObject(value)); }
private static void SetVariable(IntPtr?globals, string key, object value) { SetVariable(globals, key, PyObject.FromManagedObject(value).Handle); }