{"body": "
\n

# `collectors.shortcuts` \u2014 Useful shortcut functions\u00b6

\n

Shortcut functions for `Collector`.

\n

\n
\n`collectors.shortcuts.``get`(obj, *attributes)\u00b6
\n

  This is a shortcut that creates lambda functions for several attributes\nof an object. All functions will automatically get the attribute\u2019s value\neach time they are called.

  \n

  The results of `get` can be directly passed into a collector.

  \n

      >>> from collectors import Collector\n>>> class Spam(object):\n...     a = 1\n...     b = 2\n>>> spam = Spam()\n>>> get(spam, 'a', 'b') #doctest: +ELLIPSIS\n(('a', <function <lambda> at 0x...>), ('b', <function <lambda> at 0x...>))\n>>> # Create a collector with help of get:\n>>> c = Collector(get(spam, 'a', 'b'))\n>>> c() # Collect values.\n>>> c\n([1], [2])\n

  \n
  \n

\n\n

\n
\n`collectors.shortcuts.``get_objects`(objs, id_attr, *attributes)\u00b6
\n

  This function works similarly to `get()`, but it creates the lambda\nfunctions for multiple objects (`objs`).

  \n

  That becomes useful if you want to monitor the same attributes of several\nhomogeneous objects with one `Collector` instance.\nThe objects must have a unique attribute (`id_attr`), which will be used\nas prefix in the resulting `(name, func)` tuples. The value of that\nattribute should begin with a letter or an underscore.

  \n

      >>> from collectors import Collector\n>>> class Spam(object):\n...     a = 1\n...     b = 2\n...     def __init__(self, obj_id):\n...         self.obj_id = 'spam%d' % i\n...\n>>> spams = [Spam(i) for i in range(2)]\n>>> c = Collector(get_objects(spams, 'obj_id', 'a', 'b'))\n>>> # Attributes are now named like "objid_attrname":\n>>> c.spam0_a, c.spam0_b, c.spam1_a, c.spam1_b\n([], [], [], [])\n>>> c() # This will collect the values of a and be for each spam object.\n

  \n
  \n

\n\n

\n
\n`collectors.shortcuts.``manual`(value)\u00b6
\n

  This a simple shortcut for a function like `lambda x: x` if you want to\npass variable values manually to a monitor:

  \n

      >>> from collectors import Collector\n>>> c = Collector(('a', manual))\n>>> c(a=3)\n>>> c\n([3],)\n

  \n
  \n

\n\n
\n", "display_toc": false, "title": "`collectors.shortcuts` \u2014 Useful shortcut functions", "sourcename": "ref/shortcuts.txt", "current_page_name": "ref/shortcuts", "next": {"link": "../storage/", "title": "`collectors.storage` \u2014 Advanced storage backends"}, "rellinks": [["genindex", "General Index", "I", "index"], ["modindex", "Global Module Index", "M", "modules"], ["ref/storage", "`collectors.storage` \u2014 Advanced storage backends", "N", "next"], ["ref/core", "`collectors.core` \u2014 Core classes", "P", "previous"]], "meta": {}, "parents": [{"link": "../", "title": "API-Reference"}], "toc": "

\n
- `collectors.shortcuts` \u2014 Useful shortcut functions
\n

\n", "prev": {"link": "../core/", "title": "`collectors.core` \u2014 Core classes"}, "metatags": ""}