Как написать декоратор, восстанавливающий cwd?

Модуль path.py (который вам действительно cwd следует использовать при python-shell работе с путями в скриптах decorators Python) имеет диспетчер контекста:

subdir = d / 'subdir' #subdir is a path object, in the path.py module
with subdir:
  # here current dir is subdir

#not anymore

(кредиты decorator принадлежат this blog post Роберто Альсине)

python

decorator

cwd

2022-11-17T02:16:36+00:00