Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

method libtmux latest

QueryList.get

Retrieve exactly one object.

Source and package
Qualified name
libtmux._internal.query_list.QueryList.get
Module
libtmux._internal.query_list
Declared in
QueryList
Package
libtmux
Source
src/libtmux/_internal/query_list.py
get ( self, matcher: Callable[[T], bool] | T | None = None, default: t.Any | None = no_arg, kwargs: t.Any, ) → T | None

Examples#

>>> from libtmux._internal.query_list import QueryList
>>> from libtmux import exc
>>> qs = QueryList([{"pane_id": "%0"}, {"pane_id": "%0"}, {"pane_id": "%1"}])
>>> qs.get(pane_id="%1")
{'pane_id': '%1'}

A lookup that matches nothing says what it went looking for:

>>> try:
... qs.get(pane_id="%9")
... except exc.ObjectDoesNotExist as e:
... print(e)
No objects found: pane_id='%9'
>>> qs.get(pane_id="%9", default=None) is None
True

A lookup that matches several says how many, and for what:

>>> try:
... qs.get(pane_id="%0")
... except exc.MultipleObjectsReturned as e:
... print(e)
Multiple objects returned (2): pane_id='%0'
Type parameters
Parameters
Returns

object The single match, or default when there is no match and one was given.

Raises
  • ObjectDoesNotExist – When nothing matches and no default was passed.

  • MultipleObjectsReturned – When more than one object matches. A default does not suppress this: it stands in for an object that is absent, and an ambiguous lookup is not an absent one.

Guides#

Pages that discuss get.

Esc

Type to search.

Reference previewOpen reference