what's the command for (cd ..) in python

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Sep 10 07:11:32 EDT 2011


Waldek M. wrote:

> On Fri, 09 Sep 2011 23:03:10 +1000, Steven D'Aprano wrote:
>> But think carefully before doing this. Some functions may be confused if
>> you change directories while they are running. You may be better off
>> staying in the same directory, and adjusting the path names to the files
>> as you work with them.
> 
> Curious.
> Do you mean multi-threaded environment or even in single thread?
> If the latter is the case, I'd say those functions make
> very nasty assumptions. Who are they, anyways? ;)

The main one that comes to mind is os.walk, which has this to say:

    Caution:  if you pass a relative pathname for top, don't change the
    current working directory between resumptions of walk.  walk never
    changes the current directory, and assumes that the client doesn't
    either.

Seems like a reasonable assumption to me.

-- 
Steven




More information about the Python-list mailing list