Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python.announce > #493

pathlib 0.4

Subject pathlib 0.4
From Antoine Pitrou <solipsis@pitrou.net>
Date 2012-01-30 21:14 +0100
Newsgroups comp.lang.python.announce
Message-ID <mailman.5246.1328022057.27778.python-announce-list@python.org> (permalink)

Show all headers | View raw


Hello,

I'm releasing pathlib 0.4 for Python 3.2 and later.

* Download: http://pypi.python.org/pypi/pathlib/
  (you can probably use "pip install pathlib" or "easy_install pathlib"
   instead)

* Documentation: http://readthedocs.org/docs/pathlib/en/latest/

* Issue tracker, repository: https://bitbucket.org/pitrou/pathlib/

What is pathlib
---------------

pathlib offers a set of classes to handle filesystem paths.  It offers the
following advantages over using string objects:

* No more cumbersome use of os and os.path functions.  Everything can be
  done easily through operators, attribute accesses, and method calls.

* Embodies the semantics of different path types.  For example, comparing
  Windows paths ignores casing.

* Well-defined semantics, eliminating any warts or ambiguities (forward vs.
  backward slashes, etc.).

Examples
--------

Importing the module classes::

    >>> from pathlib import *

Listing Python source files in a directory::

    >>> p = Path('.')
    >>> [x for x in p if x.ext == '.py']
    [PosixPath('test_pathlib.py'), PosixPath('setup.py'),
     PosixPath('pathlib.py')]

Listing subdirectories::

    >>> [x for x in p if x.is_dir()]
    [PosixPath('.hg'), PosixPath('docs'), PosixPath('dist'),
     PosixPath('__pycache__'), PosixPath('build')]

Navigating inside a directory tree::

    >>> p = Path('/etc')
    >>> q = p['init.d/reboot']
    >>> q
    PosixPath('/etc/init.d/reboot')
    >>> q.resolve()
    PosixPath('/etc/rc.d/init.d/halt')

Querying path properties::

    >>> q.exists()
    True
    >>> q.is_dir()
    False
    >>> q.st_mode
    33261

Opening a file::

    >>> with q.open() as f: f.readline()
    ...
    '#!/bin/bash\n'


Regards

Antoine Pitrou.

Back to comp.lang.python.announce | Previous | Next | Find similar | Unroll thread


Thread

pathlib 0.4 Antoine Pitrou <solipsis@pitrou.net> - 2012-01-30 21:14 +0100

csiph-web