Class PyDefaultDict

  • All Implemented Interfaces:
    java.io.Serializable, java.util.concurrent.ConcurrentMap, java.util.Map, Traverseproc
    Direct Known Subclasses:
    PyDefaultDictDerived

    public class PyDefaultDict
    extends PyDictionary
    implements Traverseproc
    PyDefaultDict - This is a subclass of the builtin dict(PyDictionary) class. It supports one additional method __missing__ and adds one writable instance variable defaultFactory. The remaining functionality is the same as for the dict class. collections.defaultdict([defaultFactory[, ...]]) - returns a new dictionary-like object. The first argument provides the initial value for the defaultFactory attribute; it defaults to None. All remaining arguments are treated the same as if they were passed to the dict constructor, including keyword arguments.
    See Also:
    Serialized Form
    • Field Detail

      • TYPE

        public static final PyType TYPE
    • Constructor Detail

      • PyDefaultDict

        public PyDefaultDict()
      • PyDefaultDict

        public PyDefaultDict​(PyType subtype)
    • Method Detail

      • __reduce__

        public PyObject __reduce__()
        Description copied from class: PyObject
        Used for pickling. Default implementation calls object___reduce__.
        Overrides:
        __reduce__ in class PyObject
        Returns:
        a tuple of (class, tuple)
      • getDefaultFactory

        public PyObject getDefaultFactory()
      • setDefaultFactory

        public void setDefaultFactory​(PyObject value)
      • delDefaultFactory

        public void delDefaultFactory()
      • __finditem__

        public PyObject __finditem__​(PyObject key)
        Description copied from class: PyObject
        Very similar to the standard Python __getitem__ method. Instead of throwing a KeyError if the item isn't found, this just returns null. Classes that wish to implement __getitem__ should override this method instead (with the appropriate semantics.
        Overrides:
        __finditem__ in class PyDictionary
        Parameters:
        key - the key to lookup in this container
        Returns:
        the value corresponding to key or null if key is not found
      • get

        public PyObject get​(PyObject key,
                            PyObject defaultObj)
        Description copied from class: PyDictionary
        Return this[key] if the key exists in the mapping, defaultObj is returned otherwise.
        Overrides:
        get in class PyDictionary
        Parameters:
        key - the key to lookup in the dictionary.
        defaultObj - the value to return if the key does not exists in the mapping.