[Python-ideas] PEP 428 - object-oriented filesystem paths

Ben Finney ben+python at benfinney.id.au
Sun Oct 7 02:41:14 CEST 2012


Antoine Pitrou <solipsis at pitrou.net>
writes:

>     >>> p = Path('/home/antoine/pathlib/setup.py')
>     >>> p.name
>     'setup.py'
>     >>> p.ext
>     '.py'

The term “extension” is a barnacle from mainframe filesystems where a
filename is necessarily divided into exactly two parts, the name and the
extension. It doesn't really apply to POSIX filesystems.

On filesystems where the user has always been free to have any number of
parts in a filename, the closest concept is better referred to by the
term “suffix”::

    >>> p.suffix
    '.py'

It may be useful to add an API method to query the *sequence* of
suffixes of a filename::

    >>> p = Path('/home/antoine/pathlib.tar.gz')
    >>> p.name
    'pathlib.tar.gz'
    >>> p.suffix
    '.gz'
    >>> p.suffixes
    ['.tar', '.gz']


Thanks for keeping this proposal active, Antoine.

-- 
 \         “In any great organization it is far, far safer to be wrong |
  `\          with the majority than to be right alone.” —John Kenneth |
_o__)                                            Galbraith, 1989-07-28 |
Ben Finney




More information about the Python-ideas mailing list