Package parser_course :: Package small_parsers :: Module var_printer
[hide private]
[frames] | no frames]

Module var_printer

source code

Functions [hide private]
 
debug_print(intro_string, Vars, Env, indent=3)
Utility function for printing var values conveniently:
source code
 
print_vars(Env, Vars=(), Indent=0)
Env is a dictionary containing bindings for all the variables whose strings names are in the sequence of strings Vars (which may be a singleton string as well).
source code
Function Details [hide private]

debug_print(intro_string, Vars, Env, indent=3)

source code 

Utility function for printing var values conveniently:

 -- C{intro_string}: arbitrary label of type string.  Will
    be printed as prefix to the info below.  Usually the name
    of the function calling C{debug_print}, but can be the
    empty string.
 __ C{Vars}:  A tuple of varnames, that is, a tuple of expressions
    that evaluate to var names.
 -- C{Env}: A dictionary of variable name value pairs, usually
     by calling C{vars()}.

For example:

  >>> var_printer.debug_print('scanner', ('goal_cat','index'),vars())

prints:

  scanner
     goal_cat: np
     index   : 0

if the values of the variables goal_cat and index in environment vars() are 'np' and '0' respectively. Note the default indent of 3.

print_vars(Env, Vars=(), Indent=0)

source code 

Env is a dictionary containing bindings for all the variables whose strings names are in the sequence of strings Vars (which may be a singleton string as well). Env is usually gotten by calling vars(). So a typical call:

  >>> print_vars(vars(),('foo','foobar'))
  foo   : 'xxx'
  foobar: 'yyyyy'

If Vars is empty, all the keys of Env are printed.