Why doesn't Python remember the initial directory?
roy at panix.com
Mon Aug 20 15:58:15 CEST 2012
In article <k0tf8g$adc$1 at news.albasani.net>,
Walter Hurry <walterhurry at lavabit.com> wrote:
> It is difficult to think of a sensible use for os.chdir, IMHO.
It is true that you can mostly avoid chdir() by building absolute
pathnames, but it's often more convenient to just cd somewhere and use
names relative to that. Fabric (a very cool tool for writing remote
sysadmin scripts), gives you a cd() command which is a context manager,
making it extra convenient.
Also, core files get created in the current directory. Sometimes
daemons will cd to some fixed location to make sure that if they dump
core, it goes in the right place.
On occasion, you run into (poorly designed, IMHO) utilities which insist
of reading or writing a file in the current directory. If you're
invoking one of those, you may have no choice but to chdir() to the
right place before running them.
More information about the Python-list