[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: the mystery of dirname

MRAB

2/20/2010 5:49:00 PM

Shashwat Anand wrote:
> basically I infer that : dirname = path - basename, like for path =
> '//x', basename = x, hence dirname = '//'
>
[snip]
Basically, os.path.dirname() should return the directory name, which
means dropping everything after the last slash, and also the last slash.
However, there's the special case where the name is in the root
directory, and you want to retain the slash(es).

When building a path (os.path.join()) you want to join the parts with a
single slash between them, but there's the special case when a part is
the root directory, and you don't want to add a slash between them, eg
os.part.join('/x', 'y') should return '/x/y', but os.part.join('/', 'x')
should return '/x'.