Next / Previous / Contents / Shipman's homepage

21.14. locals(): Dictionary of local name bindings

This function returns a dictionary containing the names and values of all variables in the local namespace. An example:

>>> def f(a, b=1):
...     c=2
...     print locals()
>>> f(5)
{'a': 5, 'c': 2, 'b': 1}

For related functions, see Section 21.5, “dir(): Display a namespace's names” and Section 21.9, “globals(): Dictionary of global name bindings”.