def cd_to(path, mkdir=False):
    """make a generator like cd, but use it for function

    Usage::

        >>> @cd_to("/")
        ... def say_where():
        ...     print(os.getcwd())
        ...
        >>> say_where()
        /

    """
    def cd_to_decorator(func):
        @functools.wraps(func)
        def _cd_and_exec(*args, **kwargs):
            with cd(path, mkdir):
                return func(*args, **kwargs)
        return _cd_and_exec
    return cd_to_decorator
def cd_to ( path , mkdir = False ) : def cd_to_decorator ( func ) : @ functools . wraps ( func ) def _cd_and_exec ( * args , ** kwargs ) : with cd ( path , mkdir ) : return func ( * args , ** kwargs ) return _cd_and_exec return cd_to_decorator
make a generator like cd, but use it for function

    Usage::

        >>> @cd_to("/")
        ... def say_where():
        ...     print(os.getcwd())
        ...
        >>> say_where()
        /