Pelokalan
Python ID
id en
Masuk
Proyek
c-api__dict.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
Dictionary objects
This subtype of :c:type:`PyObject` represents a Python dictionary object.
This instance of :c:type:`PyTypeObject` represents the Python dictionary type. This is the same object as :class:`dict` in the Python layer.
Return true if *p* is a dict object or an instance of a subtype of the dict type. This function always succeeds.
Return true if *p* is a dict object, but not an instance of a subtype of the dict type. This function always succeeds.
Return a :class:`types.MappingProxyType` object for a mapping which enforces read-only behavior. This is normally used to create a view to prevent modification of the dictionary for non-dynamic class types.
The type object for mapping proxy objects created by :c:func:`PyDictProxy_New` and for the read-only ``__dict__`` attribute of many built-in types. A :c:type:`PyDictProxy_Type` instance provides a dynamic, read-only view of an underlying dictionary: changes to the underlying dictionary are reflected in the proxy, but the proxy itself does not support mutation operations. This corresponds to :class:`types.MappingProxyType` in Python.
This is the same as :c:func:`PyDict_Contains`, but *key* is specified as a :c:expr:`const char*` UTF-8 encoded bytes string, rather than a :c:expr:`PyObject*`.
This is the same as :c:func:`PyDict_SetItem`, but *key* is specified as a :c:expr:`const char*` UTF-8 encoded bytes string, rather than a :c:expr:`PyObject*`.
This is the same as :c:func:`PyDict_DelItem`, but *key* is specified as a :c:expr:`const char*` UTF-8 encoded bytes string, rather than a :c:expr:`PyObject*`.
Return a new :term:`strong reference` to the object from dictionary *p* which has a key *key*:
See also the :c:func:`PyObject_GetItem` function.
Lihat juga fungsi :c:func:`PyObject_GetItem`.
Return a :term:`borrowed reference` to the object from dictionary *p* which has a key *key*. Return ``NULL`` if the key *key* is missing *without* setting an exception.
Exceptions that occur while this calls :meth:`~object.__hash__` and :meth:`~object.__eq__` methods are silently ignored. Prefer the :c:func:`PyDict_GetItemWithError` function instead.
This is the same as :c:func:`PyDict_GetItem`, but *key* is specified as a :c:expr:`const char*` UTF-8 encoded bytes string, rather than a :c:expr:`PyObject*`.
Exceptions that occur while this calls :meth:`~object.__hash__` and :meth:`~object.__eq__` methods or while creating the temporary :class:`str` object are silently ignored. Prefer using the :c:func:`PyDict_GetItemWithError` function with your own :c:func:`PyUnicode_FromString` *key* instead.
Similar to :c:func:`PyDict_GetItemRef`, but *key* is specified as a :c:expr:`const char*` UTF-8 encoded bytes string, rather than a :c:expr:`PyObject*`.
For clarity: if you have a strong reference to *default_value* before calling this function, then after it returns, you hold a strong reference to both *default_value* and *\*result* (if it's not ``NULL``). These may refer to the same object: in that case you hold two separate references to it.
Similar to :c:func:`PyDict_Pop`, but *key* is specified as a :c:expr:`const char*` UTF-8 encoded bytes string, rather than a :c:expr:`PyObject*`.
Return a :c:type:`PyListObject` containing all the items from the dictionary.
Return a :c:type:`PyListObject` containing all the keys from the dictionary.
Return a :c:type:`PyListObject` containing all the values from the dictionary *p*.
Iterate over all key-value pairs in the dictionary *p*. The :c:type:`Py_ssize_t` referred to by *ppos* must be initialized to ``0`` prior to the first call to this function to start the iteration; the function returns true for each pair in the dictionary, and false once all pairs have been reported. The parameters *pkey* and *pvalue* should either point to :c:expr:`PyObject*` variables that will be filled in with each key and value, respectively, or may be ``NULL``. Any references returned through them are borrowed. *ppos* should not be altered during iteration. Its value represents offsets within the internal dictionary structure, and since the structure is sparse, the offsets are not consecutive.
PyObject *key, *value; Py_ssize_t pos = 0; while (PyDict_Next(self->dict, &pos, &key, &value)) { /* do something interesting with the values... */ ... }
PyObject *key, *value; Py_ssize_t pos = 0; while (PyDict_Next(self->dict, &pos, &key, &value)) { long i = PyLong_AsLong(value); if (i == -1 && PyErr_Occurred()) { return -1; } PyObject *o = PyLong_FromLong(i + 1); if (o == NULL) return -1; if (PyDict_SetItem(self->dict, key, o) < 0) { Py_DECREF(o); return -1; } Py_DECREF(o); }
PyObject *key, *value; Py_ssize_t pos = 0; while (PyDict_Next(self->dict, &pos, &key, &value)) { long i = PyLong_AsLong(value); if (i == -1 && PyErr_Occurred()) { return -1; } PyObject *o = PyLong_FromLong(i + 1); if (o == NULL) return -1; if (PyDict_SetItem(self->dict, key, o) < 0) { Py_DECREF(o); return -1; } Py_DECREF(o); }
On the free-threaded build, this function can be used safely inside a critical section. However, the references returned for *pkey* and *pvalue* are :term:`borrowed <borrowed reference>` and are only valid while the critical section is held. If you need to use these objects outside the critical section or when the critical section can be suspended, create a :term:`strong reference <strong reference>` (for example, using :c:func:`Py_NewRef`).
Iterate over mapping object *b* adding key-value pairs to dictionary *a*. *b* may be a dictionary, or any object supporting :c:func:`PyMapping_Keys` and :c:func:`PyObject_GetItem`. If *override* is true, existing pairs in *a* will be replaced if a matching key is found in *b*, otherwise pairs will only be added if there is not a matching key in *a*. Return ``0`` on success or ``-1`` if an exception was raised.
Update or merge into dictionary *a*, from the key-value pairs in *seq2*. *seq2* must be an iterable object producing iterable objects of length 2, viewed as key-value pairs. In case of duplicate keys, the last wins if *override* is true, else the first wins. Return ``0`` on success or ``-1`` if an exception was raised. Equivalent Python (except for the return value)::
If *event* is ``PyDict_EVENT_DEALLOCATED``, taking a new reference in the callback to the about-to-be-destroyed dictionary will resurrect it and prevent it from being freed at this time. When the resurrected object is destroyed later, any watcher callbacks active at that time will be called again.
Dictionary view objects
Type object for a view of dictionary keys. In Python, this is the type of the object returned by :meth:`dict.keys`.
Type object for a view of dictionary values. In Python, this is the type of the object returned by :meth:`dict.values`.
Type object for a view of dictionary items. In Python, this is the type of the object returned by :meth:`dict.items`.
Frozen dictionary objects
This instance of :c:type:`PyTypeObject` represents the Python frozen dictionary type. This is the same object as :class:`frozendict` in the Python layer.
Return true if *p* is a :class:`dict` object, a :class:`frozendict` object, or an instance of a subtype of the :class:`!dict` or :class:`!frozendict` type. This function always succeeds.
Return true if *p* is a :class:`dict` object or a :class:`frozendict` object, but not an instance of a subtype of the :class:`!dict` or :class:`!frozendict` type. This function always succeeds.
Return true if *p* is a :class:`frozendict` object or an instance of a subtype of the :class:`!frozendict` type. This function always succeeds.
Return true if *p* is a :class:`frozendict` object, but not an instance of a subtype of the :class:`!frozendict` type. This function always succeeds.
Type object for ordered dictionaries. This is the same object as :class:`collections.OrderedDict` in the Python layer.
Return true if *od* is an ordered dictionary object or an instance of a subtype of the :class:`~collections.OrderedDict` type. This function always succeeds.
Return true if *od* is an ordered dictionary object, but not an instance of a subtype of the :class:`~collections.OrderedDict` type. This function always succeeds.
object
objek