Why doesn't Python remember the initial directory?

Walter Hurry walterhurry at lavabit.com
Mon Aug 20 15:49:04 CEST 2012


On Mon, 20 Aug 2012 13:14:02 +0000, Steven D'Aprano wrote:

> On Mon, 20 Aug 2012 12:56:42 +0100, andrea crotti wrote:
> 
>> In the specific case there is absolutely no use of os.chdir, since you
>> can:
>> - use absolute paths - things like subprocess.Popen accept a cwd
>> argument - at worst you can chdir back to the previous position right
>> after the broken thing that require a certain path that you are calling
>> is run
> 
> 
> I wouldn't say so much that there's "absolutely no use", it's more that
> there are other, safer, ways to get the same result.
> 
> As I understand it, os.chdir is more for the convenience of sys admins
> who want to write quick scripts in Python than a function intended to be
> used in libraries or major applications.
> 

I don't disagree, but in my experience few sysadmins use Python; they use 
shell scripts. And these seldom do a 'cd' anyway - they will normally 
operate irrespective of the current working directory.

It is difficult to think of a sensible use for os.chdir, IMHO.

> An interesting question is, what do other languages do in this case?


More information about the Python-list mailing list