the mystery of dirname()

Shashwat Anand anand.shashwat at gmail.com
Sat Feb 20 13:34:14 EST 2010


got it. thanks. :)


On Sat, Feb 20, 2010 at 11:19 PM, MRAB <python at mrabarnett.plus.com> wrote:

> 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'.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100221/59ee7178/attachment-0001.html>


More information about the Python-list mailing list