Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé
Module « zipfile » Python 3.13.2

Classe « Path »

Informations générales

Héritage

builtins.object
    Path

Définition

class Path(builtins.object):

help(Path)

A :class:`importlib.resources.abc.Traversable` interface for zip files.

Implements many of the features users enjoy from
:class:`pathlib.Path`.

Consider a zip file with this structure::

    .
    ├── a.txt
    └── b
        ├── c.txt
        └── d
            └── e.txt

>>> data = io.BytesIO()
>>> zf = ZipFile(data, 'w')
>>> zf.writestr('a.txt', 'content of a')
>>> zf.writestr('b/c.txt', 'content of c')
>>> zf.writestr('b/d/e.txt', 'content of e')
>>> zf.filename = 'mem/abcde.zip'

Path accepts the zipfile object itself or a filename

>>> path = Path(zf)

From there, several path operations are available.

Directory iteration (including the zip file itself):

>>> a, b = path.iterdir()
>>> a
Path('mem/abcde.zip', 'a.txt')
>>> b
Path('mem/abcde.zip', 'b/')

name property:

>>> b.name
'b'

join with divide operator:

>>> c = b / 'c.txt'
>>> c
Path('mem/abcde.zip', 'b/c.txt')
>>> c.name
'c.txt'

Read text:

>>> c.read_text(encoding='utf-8')
'content of c'

existence:

>>> c.exists()
True
>>> (b / 'missing.txt').exists()
False

Coercion to string:

>>> import os
>>> str(c).replace(os.sep, posixpath.sep)
'mem/abcde.zip/b/c.txt'

At the root, ``name``, ``filename``, and ``parent``
resolve to the zipfile.

>>> str(path)
'mem/abcde.zip/'
>>> path.name
'abcde.zip'
>>> path.filename == pathlib.Path('mem/abcde.zip')
True
>>> str(path.parent)
'mem'

If the zipfile has no filename, such attributes are not
valid and accessing them will raise an Exception.

>>> zf.filename = None
>>> path.name
Traceback (most recent call last):
...
TypeError: ...

>>> path.filename
Traceback (most recent call last):
...
TypeError: ...

>>> path.parent
Traceback (most recent call last):
...
TypeError: ...

# workaround python/cpython#106763
>>> pass

Constructeur(s)

Signature du constructeur Description
__init__(self, root, at='')

Liste des propriétés

Nom de la propriétéDescription
filename
name
parent
stem
suffix
suffixes

Liste des opérateurs

Signature de l'opérateur Description
__eq__(self, other)
__truediv__(self, *other)

Opérateurs hérités de la classe object

__ge__, __gt__, __le__, __lt__, __ne__

Liste des méthodes

Toutes les méthodes Méthodes d'instance Méthodes statiques Méthodes dépréciées
Signature de la méthodeDescription
__hash__(self)
__repr__(self)
__str__(self)
exists(self)
glob(self, pattern)
is_dir(self)
is_file(self)
is_symlink(self)
iterdir(self)
joinpath(self, *other)
match(self, path_pattern)
open(self, mode='r', *args, pwd=None, **kwargs)
read_bytes(self)
read_text(self, *args, **kwargs)
relative_to(self, other, *extra)
rglob(self, pattern)

Méthodes héritées de la classe object

__delattr__, __dir__, __format__, __getattribute__, __getstate__, __init_subclass__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Vous êtes un professionnel et vous avez besoin d'une formation ? Sensibilisation à
l'Intelligence Artificielle
Voir le programme détaillé