PyDict_Items() private méthode

private PyDict_Items ( IntPtr pointer ) : IntPtr
pointer IntPtr
Résultat IntPtr
Exemple #1
0
        /// <summary>
        /// Items Method
        /// </summary>
        ///
        /// <remarks>
        /// Returns a sequence containing the items of the dictionary.
        /// </remarks>
        public PyObject Items()
        {
            IntPtr items = Runtime.PyDict_Items(obj);

            if (items == IntPtr.Zero)
            {
                throw new PythonException();
            }
            return(new PyObject(items));
        }
Exemple #2
0
        /// <summary>
        /// Items Method
        /// </summary>
        /// <remarks>
        /// Returns a sequence containing the items of the dictionary.
        /// </remarks>
        public PyObject Items()
        {
            var items = Runtime.PyDict_Items(this.Reference);

            try
            {
                if (items.IsNull())
                {
                    throw new PythonException();
                }

                return(items.MoveToPyObject());
            }
            finally
            {
                items.Dispose();
            }
        }
Exemple #3
0
        private static Dictionary <PyString, PyObject> GetDotNetModules()
        {
            BorrowedReference pyModules = Runtime.PyImport_GetModuleDict();

            using var items = Runtime.PyDict_Items(pyModules);
            nint length = Runtime.PyList_Size(items.BorrowOrThrow());

            Debug.Assert(length >= 0);
            var modules = new Dictionary <PyString, PyObject>();

            for (nint i = 0; i < length; i++)
            {
                BorrowedReference item   = Runtime.PyList_GetItem(items.Borrow(), i);
                BorrowedReference name   = Runtime.PyTuple_GetItem(item, 0);
                BorrowedReference module = Runtime.PyTuple_GetItem(item, 1);
                if (ManagedType.IsInstanceOfManagedType(module))
                {
                    modules.Add(new PyString(name), new PyObject(module));
                }
            }
            return(modules);
        }