Tag Archives: directory

Safe Directory Hopping “with” Python

Some applications need hopping around a lot between different current working directories (CWD). If you are writing such one, you might get worried that at some point control is lost and the CWD might differ from what you expected. This could certainly lead to potentially harmful consequences.

Since Python 2.5 there is a really cool feature: the with statement. There is a nice article by Fredrik Lundh [1] explaining how it works. Here I present a way to keep control over your application’s CWD making use of it.

Continue reading