[Python-ideas] os.path.join() failure

Aahz aahz at pythoncraft.com
Tue Oct 2 15:07:57 CEST 2007


On Tue, Oct 02, 2007, Greg Ewing wrote:
> Steven Bethard wrote:
>>
>> I write quite a few Windows paths, and probably make the
>> final-backslash mistake once a week.
>
> If you were using os.path.join(), as you should be, you wouldn't ever
> have to write a trailing backslash in a path in the first place. Or
> any backslashes at all, for that matter.

Wrong.  And I just got bitten by this yesterday (no backslashes at all).
Consider the difference between

cp -a foo bar

and

cp -a foo/ bar

The two are almost identical *except* when foo is a symlink to a
directory, then the first form copies the symlink instead of giving a
brand-new directory.  Which, since foo/ is a template dir that gets
modified after copying was a very bad thing.  (We moved servers around
over the weekend and for convenience's sake made foo a symlink to a new
location.)

And yes, we *were* using os.path.join().  So trailing slashes (or
backslashes) are in fact sometimes required.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.



More information about the Python-ideas mailing list