示例#1
0
        /// <summary>
        /// Get Method
        /// </summary>
        /// <remarks>
        /// Obtain the value of the variable of given name,
        /// and convert the result to a Managed Object of given type.
        /// If the variable does not exist, throw an Exception.
        /// </remarks>
        public T Get <T>(string name)
        {
            Check();
            PyObject pyObj = Get(name);

            if (pyObj == null)
            {
                return(default(T));
            }
            return(pyObj.As <T>());
        }
示例#2
0
        /// <summary>
        /// Execute method
        /// </summary>
        /// <remarks>
        /// Execute a Python ast and return the result as a PyObject,
        /// and convert the result to a Managed Object of given type.
        /// The ast can be either an expression or stmts.
        /// </remarks>
        public T Execute <T>(PyObject script, PyDict locals = null)
        {
            Check();
            PyObject pyObj = Execute(script, locals);

            if (pyObj == null)
            {
                return(default(T));
            }
            var obj = pyObj.As <T>();

            return(obj);
        }