code: def dyn(d, **kw):                                               # {{{1
    
  
    old = { k:d[k] for k in kw }
    try:
      d.update(kw)
      yield
    finally:
      d.update(old)
docs: Pseudo-dynamic variables.
  
    >>> SOME_VAR = 42
    >>> with dyn(vars(), SOME_VAR = 37): SOME_VAR
    37
    >>> SOME_VAR
    42
  
    >>> import threading
    >>> D = threading.local()
    >>> D.x, D.y = 1, 2
    >>> with dyn(vars(D), x = 3, y = 4): (D.x, D.y)
    (3, 4)
    >>> (D.x, D.y)
    (1, 2)