core icon indicating copy to clipboard operation
core copied to clipboard

Should we extensively use pushd_popd instead of try ... catch ... finally os.chdir() pattern?

Open kba opened this issue 2 years ago • 2 comments

          > Should we extensively use pushd_popd instead of try ... catch ... finally os.chdir() pattern?

Not without adapting pushd_popd first. However, I don't want to mess with that to not break something else.

Originally posted by @MehmedGIT in https://github.com/OCR-D/core/issues/987#issuecomment-1479681602

kba avatar Mar 22 '23 16:03 kba

Would working_directory be a better name for it?

with working_directory("/foo/bar"):
  do_something()

mikegerber avatar Mar 23 '23 17:03 mikegerber

Python 3.11's contextlib now has chdir. (Sadly, jazzband's contextlib2 does not have a backport yet and the project seems to lacking behind. That would have been a nice solution.)

mikegerber avatar Mar 24 '23 15:03 mikegerber