Exemple #1
0
        /// <summary>
        ///     Get a PyObject from a list
        /// </summary>
        /// <typeparam name="TItem"></typeparam>
        /// <param name="value"></param>
        /// <returns></returns>
        public PyObject From <TItem>(IEnumerable <TItem> value)
        {
            var result = new PyObject(this, Py.PyList_New(value.Count()), true);

            for (var i = 0; i < value.Count(); i++)
            {
                var pyItem = From(value.ElementAt(i));

                if (pyItem == null)
                {
                    return(PyZero);
                }

                // PyList_SetItem steals a reference, this makes sure we dont free it later
                Py.Py_IncRef(pyItem);

                if (Py.PyList_SetItem(result, i, pyItem) == -1)
                {
                    return(PyZero);
                }
            }

            return(result);
        }
Exemple #2
0
 /// <summary>
 ///     Get a PyObject from a double
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public PyObject From(double value)
 {
     // Note: Caching double's has no use due to rounding errors
     return(new PyObject(this, Py.PyFloat_FromDouble(value), true));
 }