Skip to content

Instantly share code, notes, and snippets.

@kosmikko
Created September 23, 2010 06:29
Show Gist options
  • Select an option

  • Save kosmikko/593224 to your computer and use it in GitHub Desktop.

Select an option

Save kosmikko/593224 to your computer and use it in GitHub Desktop.
def run_in_namespace(namespace):
"""
Decorator for executing a function in a given namespace, then return back to the
current namescape.
"""
def decorator(function):
def wrapper(*args, **kwargs):
current_namespace = namespace_manager.get_namespace()
try:
current_namespace = namespace_manager.get_namespace()
namespace_manager.set_namespace(namespace)
return function(*args, **kwargs)
finally:
namespace_manager.set_namespace(current_namespace)
return wrapper
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment