optunity.util module

optunity.util.DocumentedNamedTuple(docstring, *ntargs)[source]

Factory function to construct collections.namedtuple with a docstring. Useful to attach meta-information to data structures.

Inspired by http://stackoverflow.com/a/1606478

optunity.util.get_default_args(func)[source]

returns a dictionary of arg_name:default_values for the input function

optunity.util.getargspec(obj)[source]
Get the names and default values of a callable’s
arguments

A tuple of four things is returned: (args, varargs, varkw, defaults).

  • args is a list of the argument names (it may contain nested lists).
  • varargs and varkw are the names of the * and ** arguments or None.
  • defaults is a tuple of default argument values or None if there are no default arguments; if this tuple has n elements, they correspond to the last n elements listed in args.

Unlike inspect.getargspec(), can return argument specification for functions, methods, callable objects, and classes. Does not support builtin functions or methods.

optunity.util.nth(iterable, n)[source]

Returns the nth item from iterable.