[Python-ideas] Python-ideas os.listdir with current working directory as?default

Cameron Simpson cs at zip.com.au
Mon May 25 01:05:57 CEST 2009


On 24May2009 21:40, Antoine Pitrou <solipsis at pitrou.net> wrote:
| Tarek Ziadé <ziade.tarek at ...> writes:
| > As soon as your program is working with the filesystem, and is
| > navigating into it by calling APIs like os.chdir, os.getcwd, etc,
| > you have good chances to end up calling os.listdir on the current
| > directory, and specifying os.curdir becomes superfluous imho
| > because you know you are in os.curdir.
| 
| You'd better be careful with it. The "current directory" is process-wide
| and so modifying it in a thread will affect all other threads in your
| program. I'm not saying all programs have this characteristic, but relying
| on the current directory rather than explicit paths isn't always a good idea...

True, but if he's doing that the issue is already there.
Changing listdir(curdir()) into listdir() isn't going the change any
semantics.

On the other hand, I've several times been bitten by shell scripts that
change directory before doing something and in so doing quietly break
some relative filenames... Same problem.

Still, the problem's not with giving listdir a default, specificly.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Trust the computer industry to shorten Year 2000 to Y2K. It was this
thinking that caused the problem in the first place.
- Mark Ovens <marko at uk.radan.com>



More information about the Python-ideas mailing list