Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • BackTrack 5 R2
  • Wine 1.4 / 1.5.5
  • Mozilla Firefox 12...
  • Ubuntu 11.04
  • Angry Birds 1.1.2.1
  • Ubuntu 10.04.4 LTS
  • Linux Kernel 3.4
  • Ubuntu Manual 10.10
  • Adobe Flash Player...
  • Pidgin 2.10.4
  • Home > Linux > Programming > Libraries

    pathlib 0.5

    Download button

    No screenshots available
    Downloads: 63  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Antoine Pitrou | More programs
    MIT/X Consortium Lic... / FREE
    February 4th, 2012, 11:15 GMT [view history]
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    pathlib description

    Object-oriented filesystem paths

    pathlib is a Python module that 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.).

    Install

    easy_install pathlib or pip install pathlib should do the trick.

    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'


    Documentation

    The full documentation can be read at Read the Docs.


    Product's homepage

    Requirements:

    · Python

    What's New in This Release: [ read full changelog ]

    · Add Path.mkdir().
    · Add Python 2.7 compatibility by Michele Lacchia.
    · Make parent() raise ValueError when the level is greater than the path length.

      


    TAGS:

    object-oriented filesystem | filesystem paths | object-oriented | filesystem | paths



    HTML code for linking to this page:


    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM