dictionary

Module

Implements Python Dictionary.

You can import these APIs from the python package. For example:

from python.dictionary import Dictionary

Dictionary

A Python dictionary.

Fields:

  • ​py_object (PyObjectPtr): The underlying pyobject pointer of this dictionary.

Implemented traits:

AnyType

Methods:

__init__

__init__(inout self: Self, dict: PyObjectPtr)

Initialize the dictionary with the given pyobject pointer.

Args:

  • ​dict (PyObjectPtr): The pyobject pointer used to initialize the new dictionary.

__copyinit__

__copyinit__(inout self: Self, existing: Self)

Copy the dictionary.

This increments the underlying refcount of the existing object.

Args:

  • ​existing (Self): The value to copy.

__del__

__del__(owned self: Self)

Destroy the object.

This decrements the underlying refcount of the pointed-to object.

__bool__

__bool__(self: Self) -> Bool

Whether or not the Dictionary is nonnull.

Returns:

True if the Dictionary is nonnull, False otherwise.

__getitem__

__getitem__(self: Self, key: PythonObject) -> PythonObject

Gets the object at the specified key.

Args:

  • ​key (PythonObject): The key of the value to retrieve.

Returns:

The value at the specified key.

__setitem__

__setitem__(self: Self, key: PythonObject, value: PythonObject)

Sets the value with the specified key.

Args:

  • ​key (PythonObject): The key of the value to set.
  • ​value (PythonObject): The value to store.

__setitem__(self: Self, key: PythonObject, value: Self)

Sets the value with the specified key.

Args:

  • ​key (PythonObject): The key of the value to set.
  • ​value (Self): The value to store.

__iter__

__iter__(inout self: Self) -> _PyIter

Iterate over the dictionary.

Returns:

An iterator object.

__getattr__

__getattr__(self: Self, name: StringLiteral) -> PythonObject

Return the value of the dictionary attribute with the given name.

Args:

  • ​name (StringLiteral): The name of the dictionary attribute to return.

Returns:

The value of the dictionary attribute with the given name.