Tags – Notmuch tags

class Tags(tags_p, parent=None)

Represents a list of notmuch tags

This object provides an iterator over a list of notmuch tags (which are unicode instances).

Do note that the underlying library only provides a one-time iterator (it cannot reset the iterator to the start). Thus iterating over the function will “exhaust” the list of tags, and a subsequent iteration attempt will raise a NotInitializedError. Also note, that any function that uses iteration (nearly all) will also exhaust the tags. So both:

for tag in tags: print tag

as well as:

number_of_tags = len(tags)

and even a simple:

#str() iterates over all tags to construct a space separated list
print(str(tags))

will “exhaust” the Tags. If you need to re-iterate over a list of tags you will need to retrieve a new Tags object.

Parameters:
  • tags_p (ctypes.c_void_p) – A pointer to an underlying notmuch_tags_t structure. These are not publicly exposed, so a user will almost never instantiate a Tags object herself. They are usually handed back as a result, e.g. in Database.get_all_tags(). tags_p must be valid, we will raise an NullPointerError if it is None.
  • parent – The parent object (ie Database or Message these tags are derived from, and saves a reference to it, so we can automatically delete the db object once all derived objects are dead.
TODO:

Make the iterator optionally work more than once by cache the tags in the Python object(?)

__len__()

Warning

__len__() was removed in version 0.6 as it exhausted the iterator and broke list(Tags()). Use len(list(msgs))() instead if you need to know the number of tags.

__str__()

Return str(self).