I use python a lot to automate various file management on my computer, so
@contextmanager
def cd(newdir)
prevdir = os.getcwd()
os.chdir(os.path.expanduser(newdir)
try:
yield
finally:
os.chdir(prevdir)
is my most reused function as it allows me write
with cd(newdir)
#stuff
So I'd definitely go with contextmanager/yield as my favourite syntax sugar.