Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
b6e66ebd
Kaydet (Commit)
b6e66ebd
authored
Kas 28, 2013
tarafından
Eli Bendersky
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Some minor clarifications in the documentation of pathlib + inheritance diagram
üst
81481643
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
68 deletions
+80
-68
pathlib-inheritance.png
Doc/library/pathlib-inheritance.png
+0
-0
pathlib.rst
Doc/library/pathlib.rst
+80
-68
No files found.
Doc/library/pathlib-inheritance.png
0 → 100644
Dosyayı görüntüle @
b6e66ebd
This diff was suppressed by a .gitattributes entry.
Doc/library/pathlib.rst
Dosyayı görüntüle @
b6e66ebd
...
@@ -9,15 +9,27 @@
...
@@ -9,15 +9,27 @@
.. versionadded:: 3.4
.. versionadded:: 3.4
This module offers classes representing filesystem paths with semantics
This module offers classes representing filesystem paths with semantics
appropriate for different operating systems. Path classes are divided
appropriate for different operating systems. Path classes are divided
between :ref:`pure paths <pure-paths>`, which provide purely computational
between :ref:`pure paths <pure-paths>`, which provide purely computational
operations without I/O, and :ref:`concrete paths <concrete-paths>`, which
operations without I/O, and :ref:`concrete paths <concrete-paths>`, which
inherit from pure paths but also provide I/O operations.
inherit from pure paths but also provide I/O operations.
The main point of entry is the :class:`Path` class, which will instantiate
.. image:: pathlib-inheritance.png
a :ref:`concrete path <concrete-paths>` for the current platform.
:align: center
If you've never used this module before or just aren't sure which class is
right for your task, :class:`Path` is most likely what you need. It instantiates
a :ref:`concrete path <concrete-paths>` for the platform the code is running on.
Pure paths are useful in some special cases; for example:
#. If you want to manipulate Windows paths on a Unix machine (or vice versa).
You cannot instantiate a :class:`WindowsPath` when running on Unix, but you
can instantiate :class:`PureWindowsPath`.
#. You want to make sure that your code only manipulates paths without actually
accessing the OS. In this case, instantiating one of the pure classes may be
useful since those simply don't have any OS-accessing operations.
.. note::
.. note::
This module has been included in the standard library on a
This module has been included in the standard library on a
...
@@ -86,82 +98,78 @@ Pure path objects provide path-handling operations which don't actually
...
@@ -86,82 +98,78 @@ Pure path objects provide path-handling operations which don't actually
access a filesystem. There are three ways to access these classes, which
access a filesystem. There are three ways to access these classes, which
we also call *flavours*:
we also call *flavours*:
.. class:: PurePath(*pathsegments)
.. class:: PurePosixPath
A generic class that represents the system's path flavour (instantiating
it creates either a :class:`PurePosixPath` or a :class:`PureWindowsPath`)::
A subclass of :class:`PurePath`, this path flavour represents non-Windows
filesystem paths::
>>> PurePosixPath('/etc')
PurePosixPath('/etc')
.. class:: PureWindowsPath
>>> PurePath('setup.py') # Running on a Unix machine
PurePosixPath('setup.py')
A subclass of :class:`PurePath`, this path flavour represents Windows
Each element of *pathsegments* can be either a string or bytes object
filesystem paths
::
representing a path segment; it can also be another path object
::
>>> PureWindowsPath('c:/Program Files/')
>>> PurePath('foo', 'some/path', 'bar')
PureWindowsPath('c:/Program Files')
PurePosixPath('foo/some/path/bar')
>>> PurePath(Path('foo'), Path('bar'))
PurePosixPath('foo/bar')
.. class:: PurePath
When *pathsegments* is empty, the current directory is assumed::
A generic class that represents the system's path flavour (instantiating
>>> PurePath()
it creates either a :class:`PurePosixPath` or a :class:`PureWindowsPath`)::
PurePosixPath('.')
>>> PurePath('setup.py')
When several absolute paths are given, the last is taken as an anchor
PurePosixPath('setup.py')
(mimicking :func:`os.path.join`'s behaviour)::
>>> PurePath('/etc', '/usr', 'lib64')
PurePosixPath('/usr/lib64')
>>> PureWindowsPath('c:/Windows', 'd:bar')
PureWindowsPath('d:bar')
Regardless of the system you're running on, you can instantiate all of
However, in a Windows path, changing the local root doesn't discard the
these classes, since they don't provide any operation that does system calls.
previous drive setting::
>>> PureWindowsPath('c:/Windows', '/Program Files')
PureWindowsPath('c:/Program Files')
Constructing paths
Spurious slashes and single dots are collapsed, but double dots (``'..'``)
^^^^^^^^^^^^^^^^^^
are not, since this would change the meaning of a path in the face of
symbolic links::
Path constructors accept an arbitrary number of positional arguments.
>>> PurePath('foo//bar')
When called without any argument, a path object points to the current
PurePosixPath('foo/bar')
directory::
>>> PurePath('foo/./bar')
PurePosixPath('foo/bar')
>>> PurePath('foo/../bar')
PurePosixPath('foo/../bar')
>>> PurePath()
(a naïve approach would make ``PurePosixPath('foo/../bar')`` equivalent
PurePosixPath('.')
to ``PurePosixPath('bar')``, which is wrong if ``foo`` is a symbolic link
to another directory)
Any argument can be a string or bytes object representing an arbitrary number
.. class:: PurePosixPath(*pathsegments)
of path segments, but it can also be another path object::
>>> PurePath('foo', 'some/path', 'bar')
A subclass of :class:`PurePath`, this path flavour represents non-Windows
PurePosixPath('foo/some/path/bar')
filesystem paths::
>>> PurePath(Path('foo'), Path('bar'))
PurePosixPath('foo/bar')
When several absolute paths are given, the last is taken as an anchor
>>> PurePosixPath('/etc')
(mimicking :func:`os.path.join`'s behaviour)::
PurePosixPath('/etc')
>>> PurePath('/etc', '/usr', 'lib64')
*pathsegments* is specified similarly to :class:`PurePath`.
PurePosixPath('/usr/lib64')
>>> PureWindowsPath('c:/Windows', 'd:bar')
PureWindowsPath('d:bar')
However, in a Windows path, changing the local root doesn't discard the
.. class:: PureWindowsPath(*pathsegments)
previous drive setting::
>>> PureWindowsPath('c:/Windows', '/Program Files')
A subclass of :class:`PurePath`, this path flavour represents Windows
PureWindowsPath('c:/Program Files')
filesystem paths::
Spurious slashes and single dots are collapsed, but double dots (``'..'``)
>>> PureWindowsPath('c:/Program Files/')
are not, since this would change the meaning of a path in the face of
PureWindowsPath('c:/Program Files')
symbolic links::
>>> PurePath('foo//bar')
*pathsegments* is specified similarly to :class:`PurePath`.
PurePosixPath('foo/bar')
>>> PurePath('foo/./bar')
PurePosixPath('foo/bar')
>>> PurePath('foo/../bar')
PurePosixPath('foo/../bar')
(a naïve approach would make ``PurePosixPath('foo/../bar')`` equivalent
Regardless of the system you're running on, you can instantiate all of
to ``PurePosixPath('bar')``, which is wrong if ``foo`` is a symbolic link
these classes, since they don't provide any operation that does system calls.
to another directory)
General properties
General properties
...
@@ -524,8 +532,18 @@ Concrete paths are subclasses of the pure path classes. In addition to
...
@@ -524,8 +532,18 @@ Concrete paths are subclasses of the pure path classes. In addition to
operations provided by the latter, they also provide methods to do system
operations provided by the latter, they also provide methods to do system
calls on path objects. There are three ways to instantiate concrete paths:
calls on path objects. There are three ways to instantiate concrete paths:
.. class:: Path(*pathsegments)
A subclass of :class:`PurePath`, this class represents concrete paths of
the system's path flavour (instantiating it creates either a
:class:`PosixPath` or a :class:`WindowsPath`)::
>>> Path('setup.py')
PosixPath('setup.py')
*pathsegments* is specified similarly to :class:`PurePath`.
.. class:: PosixPath
.. class:: PosixPath
(*pathsegments)
A subclass of :class:`Path` and :class:`PurePosixPath`, this class
A subclass of :class:`Path` and :class:`PurePosixPath`, this class
represents concrete non-Windows filesystem paths::
represents concrete non-Windows filesystem paths::
...
@@ -533,7 +551,9 @@ calls on path objects. There are three ways to instantiate concrete paths:
...
@@ -533,7 +551,9 @@ calls on path objects. There are three ways to instantiate concrete paths:
>>> PosixPath('/etc')
>>> PosixPath('/etc')
PosixPath('/etc')
PosixPath('/etc')
.. class:: WindowsPath
*pathsegments* is specified similarly to :class:`PurePath`.
.. class:: WindowsPath(*pathsegments)
A subclass of :class:`Path` and :class:`PureWindowsPath`, this class
A subclass of :class:`Path` and :class:`PureWindowsPath`, this class
represents concrete Windows filesystem paths::
represents concrete Windows filesystem paths::
...
@@ -541,15 +561,7 @@ calls on path objects. There are three ways to instantiate concrete paths:
...
@@ -541,15 +561,7 @@ calls on path objects. There are three ways to instantiate concrete paths:
>>> WindowsPath('c:/Program Files/')
>>> WindowsPath('c:/Program Files/')
WindowsPath('c:/Program Files')
WindowsPath('c:/Program Files')
.. class:: Path
*pathsegments* is specified similarly to :class:`PurePath`.
A subclass of :class:`PurePath`, this class represents concrete paths of
the system's path flavour (instantiating it creates either a
:class:`PosixPath` or a :class:`WindowsPath`)::
>>> Path('setup.py')
PosixPath('setup.py')
You can only instantiate the class flavour that corresponds to your system
You can only instantiate the class flavour that corresponds to your system
(allowing system calls on non-compatible path flavours could lead to
(allowing system calls on non-compatible path flavours could lead to
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment