DESCRIPTION.rst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. pathlib offers a set of classes to handle filesystem paths. It offers the
  2. following advantages over using string objects:
  3. * No more cumbersome use of os and os.path functions. Everything can be
  4. done easily through operators, attribute accesses, and method calls.
  5. * Embodies the semantics of different path types. For example, comparing
  6. Windows paths ignores casing.
  7. * Well-defined semantics, eliminating any warts or ambiguities (forward vs.
  8. backward slashes, etc.).
  9. Requirements
  10. ------------
  11. Python 3.2 or later is recommended, but pathlib is also usable with Python 2.7
  12. and 2.6.
  13. Install
  14. -------
  15. In Python 3.4, pathlib is now part of the standard library. For Python 3.3
  16. and earlier, ``easy_install pathlib`` or ``pip install pathlib`` should do
  17. the trick.
  18. Examples
  19. --------
  20. Importing the module classes::
  21. >>> from pathlib import *
  22. Listing Python source files in a directory::
  23. >>> list(p.glob('*.py'))
  24. [PosixPath('test_pathlib.py'), PosixPath('setup.py'),
  25. PosixPath('pathlib.py')]
  26. Navigating inside a directory tree::
  27. >>> p = Path('/etc')
  28. >>> q = p / 'init.d' / 'reboot'
  29. >>> q
  30. PosixPath('/etc/init.d/reboot')
  31. >>> q.resolve()
  32. PosixPath('/etc/rc.d/init.d/halt')
  33. Querying path properties::
  34. >>> q.exists()
  35. True
  36. >>> q.is_dir()
  37. False
  38. Opening a file::
  39. >>> with q.open() as f: f.readline()
  40. ...
  41. '#!/bin/bash\n'
  42. Documentation
  43. -------------
  44. The full documentation can be read at `Read the Docs
  45. <https://pathlib.readthedocs.org/>`_.
  46. Contributing
  47. ------------
  48. Main development now takes place in the Python standard library: see
  49. the `Python developer's guide <http://docs.python.org/devguide/>`_, and
  50. report issues on the `Python bug tracker <http://bugs.python.org/>`_.
  51. However, if you find an issue specific to prior versions of Python
  52. (such as 2.7 or 3.2), you can post an issue on the
  53. `BitBucket project page <https://bitbucket.org/pitrou/pathlib/>`_.
  54. History
  55. -------
  56. Version 1.0.1
  57. ^^^^^^^^^^^^^
  58. - Pull requestion #4: Python 2.6 compatibility by eevee.
  59. Version 1.0
  60. ^^^^^^^^^^^
  61. This version brings ``pathlib`` up to date with the official Python 3.4
  62. release, and also fixes a couple of 2.7-specific issues.
  63. - Python issue #20765: Add missing documentation for PurePath.with_name()
  64. and PurePath.with_suffix().
  65. - Fix test_mkdir_parents when the working directory has additional bits
  66. set (such as the setgid or sticky bits).
  67. - Python issue #20111: pathlib.Path.with_suffix() now sanity checks the
  68. given suffix.
  69. - Python issue #19918: Fix PurePath.relative_to() under Windows.
  70. - Python issue #19921: When Path.mkdir() is called with parents=True, any
  71. missing parent is created with the default permissions, ignoring the mode
  72. argument (mimicking the POSIX "mkdir -p" command).
  73. - Python issue #19887: Improve the Path.resolve() algorithm to support
  74. certain symlink chains.
  75. - Make pathlib usable under Python 2.7 with unicode pathnames (only pure
  76. ASCII, though).
  77. - Issue #21: fix TypeError under Python 2.7 when using new division.
  78. - Add tox support for easier testing.
  79. Version 0.97
  80. ^^^^^^^^^^^^
  81. This version brings ``pathlib`` up to date with the final API specified
  82. in :pep:`428`. The changes are too long to list here, it is recommended
  83. to read the `documentation <https://pathlib.readthedocs.org/>`_.
  84. .. warning::
  85. The API in this version is partially incompatible with pathlib 0.8 and
  86. earlier. Be sure to check your code for possible breakage!
  87. Version 0.8
  88. ^^^^^^^^^^^
  89. - Add PurePath.name and PurePath.anchor.
  90. - Add Path.owner and Path.group.
  91. - Add Path.replace().
  92. - Add Path.as_uri().
  93. - Issue #10: when creating a file with Path.open(), don't set the executable
  94. bit.
  95. - Issue #11: fix comparisons with non-Path objects.
  96. Version 0.7
  97. ^^^^^^^^^^^
  98. - Add '**' (recursive) patterns to Path.glob().
  99. - Fix openat() support after the API refactoring in Python 3.3 beta1.
  100. - Add a *target_is_directory* argument to Path.symlink_to()
  101. Version 0.6
  102. ^^^^^^^^^^^
  103. - Add Path.is_file() and Path.is_symlink()
  104. - Add Path.glob() and Path.rglob()
  105. - Add PurePath.match()
  106. Version 0.5
  107. ^^^^^^^^^^^
  108. - Add Path.mkdir().
  109. - Add Python 2.7 compatibility by Michele Lacchia.
  110. - Make parent() raise ValueError when the level is greater than the path
  111. length.