一图看懂 zipp 模块:ZipFile 的一些兼容子类和补充接口,资料整理+笔记(大全)

本文由 大侠(AhcaoZhu)原创,转载请声明。
链接: https://blog.csdn.net/Ahcao2008

Alt

🧊摘要

  • 全文介绍python的 zipp 模块(ZipFile 的一些兼容子类和补充接口)、函数、类及类的方法和属性。
  • 它通过代码抓取并经AI智能翻译和人工校对。
  • 是一部不可多得的权威字典类工具书。它是系列集的一部分。后续陆续发布、敬请关注。【原创:AhcaoZhu大侠】

🧊模块图

zipp-module

zipp
	◆posixpath
	◆zipfile
	zipp.py310compat

🧊类关系图

zipp-class

◆object
	◆BaseException
		◆Exception
			◆zipfile.BadZipFile
			◆zipfile.LargeZipFile
	◆_frozen_importlib.BuiltinImporter
	◆_io._IOBase
		◆_io._BufferedIOBase
			◆io.BufferedIOBase
				◆zipfile.ZipExtFile
				◆zipfile._ZipWriteFile
	◆zipfile.LZMACompressor
	◆zipfile.LZMADecompressor
	◆zipfile.ZipFile
		◆zipfile.PyZipFile
		zipp.InitializedState
			zipp.CompleteDirs
				zipp.FastLookup
	◆zipfile.ZipInfo
	◆zipfile._SharedFile
	◆zipfile._Tellable
	zipp.InitializedState
	zipp.Path

🧊模块全展开

☘️【zipp】

zipp, fullname=zipp, file=zipp_init_.py

🔵统计

序号类别数量
4str4
6list2
8dict1
9module9
10class4
11function5
12builtin_function_or_method1
13residual3
14system10
15private5
16all29

🔵常量

🔵模块

🌿1 io

io, fullname=io, file=io.py

🌿2 posixpath

posixpath, fullname=posixpath, file=posixpath.py

🌿3 zipfile

zipfile, fullname=zipfile, file=zipfile.py

🌿4 itertools

itertools, fullname=itertools

🌿5 contextlib

contextlib, fullname=contextlib, file=contextlib.py

🌿6 pathlib

pathlib, fullname=pathlib, file=pathlib.py

🌿7 re

re, fullname=re, file=re.py

🌿8 fnmatch

fnmatch, fullname=fnmatch, file=fnmatch.py

🌿9 zipp.py310compat

py310compat, fullname=zipp.py310compat, file=zipp\py310compat.py

🔵函数

🌿10 (encoding, stacklevel=2)

(encoding, stacklevel=2), module=zipp.py310compat, line:1 at ring>

🌿11 _parents(path)

parents(path), module=zipp, line:16 at site-packages\zipp_init.py

给定一个用posixpath.sep分隔元素的路径。生成该路径的所有父路径。
    >>> list(_parents('b/d'))
    ['b']
    >>> list(_parents('/b/d/'))
    ['/b']
    >>> list(_parents('b/d/f/'))
    ['b/d', 'b']
    >>> list(_parents('b'))
    []
    >>> list(_parents(''))
    []

🌿12 _ancestry(path)

ancestry(path), module=zipp, line:35 at site-packages\zipp_init.py

给定一个用osixpath.sep分隔元素的路径,生成该给定路径上所有元素。
    >>> list(_ancestry('b/d'))
    ['b/d', 'b']
    >>> list(_ancestry('/b/d/'))
    ['/b/d', '/b']
    >>> list(_ancestry('b/d/f/'))
    ['b/d/f', 'b/d', 'b']
    >>> list(_ancestry('b'))
    ['b']
    >>> list(_ancestry(''))
    []

🌿13 _difference(minuend, subtrahend)

difference(minuend, subtrahend), module=zipp, line:61 at site-packages\zipp_init.py

返回减数形式而不是减数形式的项,保持0(1)查找的顺序。

🌿14 _extract_text_encoding(encoding=None, *args, **kwargs)

extract_text_encoding(encoding=None, *args, **kwargs), module=zipp, line:171 at site-packages\zipp_init.py

🔵类

🌿15 zipp.InitializedState

InitializedState, zipp.InitializedState, module=zipp, line:-1 at site-packages\zipp_init_.py

为序列化嵌入式保存初始化状态。

🌿16 zipp.CompleteDirs

CompleteDirs, zipp.CompleteDirs, module=zipp, line:-1 at site-packages\zipp_init_.py

一个ZipFile子类,它确保隐含的目录总是包含在名称列表中。
    >>> list(CompleteDirs._implied_dirs(['foo/bar.txt', 'foo/bar/baz.txt']))
    ['foo/', 'foo/bar/']
    >>> list(CompleteDirs._implied_dirs(['foo/bar.txt', 'foo/bar/baz.txt', 'foo/bar/']))
    ['foo/']
method
1 getinfo(self, name)

kind=method class=CompleteDirs objtype=function

为隐含的dirs补充getinfo。
2 namelist(self)

kind=method class=CompleteDirs objtype=function

3 resolve_dir(self, name)

kind=method class=CompleteDirs objtype=function

如果名称代表一个目录,则返回该名称作为目录(带尾斜杠)。
class method
4 make(cls, source)

kind=class method class=CompleteDirs objtype=classmethod

给定一个源文件(filename或zipfile),返回一个适当的CompleteDirs子类。

🌿17 zipp.FastLookup

FastLookup, zipp.FastLookup, module=zipp, line:-1 at site-packages\zipp_init_.py

ZipFile子类,以确保隐式文件存在并快速解析。
method
1 namelist(self)

kind=method class=FastLookup objtype=function

🌿18 zipp.Path

Path, zipp.Path, module=zipp, line:-1 at site-packages\zipp_init_.py

zip文件的路径库兼容接口。
考虑一个zip文件,它的结构如下:
        .
        ├── a.txt
        └── b
            ├── c.txt
            └── d
                └── e.txt
    >>> data = io.BytesIO()
    >>> zf = zipfile.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接受zipfile对象本身或文件名。
    >>> root = Path(zf)
    从那里,有几个路径操作可用。
    目录迭代(包括zip文件本身):
    >>> a, b = root.iterdir()
    >>> a
    Path('mem/abcde.zip', 'a.txt')
    >>> b
    Path('mem/abcde.zip', 'b/')
    name 属性:
    >>> b.name
    'b'
    用除号操作符连接:
    >>> c = b / 'c.txt'
    >>> c
    Path('mem/abcde.zip', 'b/c.txt')
    >>> c.name
    'c.txt'
    读入文本:
    >>> c.read_text(encoding='utf-8')
    'content of c'
    存在性:
    >>> c.exists()
    True
    >>> (b / 'missing.txt').exists()
    False
    强制转换为字符串:
    >>> import os
    >>> str(c).replace(os.sep, posixpath.sep)
    'mem/abcde.zip/b/c.txt'
    在根目录中,``name``, ``filename`` 和 ``parent`` 解析为zip文件。
    注意,这些属性是无效的,如果zipfile没有文件名,将引发 ``ValueError`` 。
    >>> root.name
    'abcde.zip'
    >>> str(root.filename).replace(os.sep, posixpath.sep)
    'mem/abcde.zip'
    >>> str(root.parent)
    'mem'
property

1 filename=<property object at 0x00000243651E7598> kind:property type:property class:<class ‘zipp.Path’>
2 name=<property object at 0x00000243651E7458> kind:property type:property class:<class ‘zipp.Path’>
3 parent=<property object at 0x00000243651E75E8> kind:property type:property class:<class ‘zipp.Path’>
4 stem=<property object at 0x00000243651E7548> kind:property type:property class:<class ‘zipp.Path’>
5 suffix=<property object at 0x00000243651E74A8> kind:property type:property class:<class ‘zipp.Path’>
6 suffixes=<property object at 0x00000243651E74F8> kind:property type:property class:<class ‘zipp.Path’>

method
7 read_text(self, *args, **kwargs)

kind=method class=Path objtype=function

8 read_bytes(self)

kind=method class=Path objtype=function

9 relative_to(self, other, *extra)

kind=method class=Path objtype=function

10 match(self, path_pattern)

kind=method class=Path objtype=function

11 is_symlink(self)

kind=method class=Path objtype=function

返回该路径是否为符号链接。总是false (python/cpython#82102)。
12 match(self, path_pattern)

kind=method class=Path objtype=function

13 glob(self, pattern)

kind=method class=Path objtype=function

14 rglob(self, pattern)

kind=method class=Path objtype=function

15 open(self, mode=‘r’, *args, pwd=None, **kwargs)

kind=method class=Path objtype=function

通过将参数传递给io.TextIOWrapper(),以文本或二进制形式按照 ``pathlib.Path.open()`` 的语义打开此条目。
16 is_dir(self)

kind=method class=Path objtype=function

17 is_file(self)

kind=method class=Path objtype=function

18 exists(self)

kind=method class=Path objtype=function

19 iterdir(self)

kind=method class=Path objtype=function

🔵内嵌函数或方法

19 _dedupe <built-in method fromkeys of type object at 0x00007FFC7765B860>

🔵私有或局部

20 _parents <function _parents at 0x00000243651A24C8>
21 _ancestry <function _ancestry at 0x00000243651E2948>
22 _dedupe <built-in method fromkeys of type object at 0x00007FFC7765B860>
23 _difference <function _difference at 0x00000243651E2828>
24 _extract_text_encoding <function _extract_text_encoding at 0x00000243651E2A68>

☘️【io】

io, fullname=io, file=io.py

☘️【posixpath】

posixpath, fullname=posixpath, file=posixpath.py

☘️【zipfile】

zipfile, fullname=zipfile, file=zipfile.py

☘️【itertools】

itertools, fullname=itertools

☘️【contextlib】

contextlib, fullname=contextlib, file=contextlib.py

☘️【pathlib】

pathlib, fullname=pathlib, file=pathlib.py

☘️【re】

re, fullname=re, file=re.py

☘️【fnmatch】

fnmatch, fullname=fnmatch, file=fnmatch.py

☘️【zipp.py310compat】

py310compat, fullname=zipp.py310compat, file=zipp\py310compat.py

☘️【sys】

sys, fullname=sys

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AhcaoZhu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值