def static_vars(**kwargs):
  """
  Attach static variables to a function.

  Usage:
    @static_vars(k1=v1, k2=k2, ...)
    def myfunc(...):
      myfunc.k1...
  
  Parameters:
    **kwargs  Keyword=value pairs converted to static variables in decorated
              function.

  Returns:
    decorate
  """
  def decorate(func):
    for k, v in kwargs.items():
      setattr(func, k, v)
    return func
  return decorate