Skip to content

Commit 5219b7e

Browse files
committed
13.8小节完成
1 parent 7e7e700 commit 5219b7e

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed
Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
11
==============================
2-
13.8 创建和解压压缩文件
2+
13.8 创建和解压归档文件
33
==============================
44

55
----------
66
问题
77
----------
8-
You need to create or unpack archives in common formats (e.g., .tar, .tgz, or .zip).
8+
你需要创建或解压常见格式的归档文件(比如.tar, .tgz或.zip
99

1010
|
1111
1212
----------
1313
解决方案
1414
----------
15-
The shutil module has two functions—make_archive() and unpack_archive()—that
16-
do exactly what you want. For example:
15+
``shutil`` 模块拥有两个函数—— ``make_archive()`` 和 ``unpack_archive()`` 可派上用场。
16+
例如:
1717

18-
>>> import shutil
19-
>>> shutil.unpack_archive('Python-3.3.0.tgz')
18+
.. code-block:: python
2019
21-
>>> shutil.make_archive('py33','zip','Python-3.3.0')
22-
'/Users/beazley/Downloads/py33.zip'
23-
>>>
20+
>>> import shutil
21+
>>> shutil.unpack_archive('Python-3.3.0.tgz')
2422
25-
The second argument to make_archive() is the desired output format. To get a list of
26-
supported archive formats, use get_archive_formats(). For example:
23+
>>> shutil.make_archive('py33','zip','Python-3.3.0')
24+
'/Users/beazley/Downloads/py33.zip'
25+
>>>
2726
28-
>>> shutil.get_archive_formats()
29-
[('bztar', "bzip2'ed tar-file"), ('gztar', "gzip'ed tar-file"),
30-
('tar', 'uncompressed tar file'), ('zip', 'ZIP file')]
31-
>>>
27+
``make_archive()`` 的第二个参数是期望的输出格式。
28+
可以使用 ``get_archive_formats()`` 获取所有支持的归档格式列表。例如:
29+
30+
.. code-block:: python
31+
32+
>>> shutil.get_archive_formats()
33+
[('bztar', "bzip2'ed tar-file"), ('gztar', "gzip'ed tar-file"),
34+
('tar', 'uncompressed tar file'), ('zip', 'ZIP file')]
35+
>>>
3236
3337
|
3438
3539
----------
3640
讨论
3741
----------
38-
Python has other library modules for dealing with the low-level details of various archive
39-
formats (e.g., tarfile, zipfile, gzip, bz2, etc.). However, if all you’re trying to do is
40-
make or extract an archive, there’s really no need to go so low level. You can just use
41-
these high-level functions in shutil instead.
42-
The functions have a variety of additional options for logging, dryruns, file permissions,
43-
and so forth. Consult the shutil library documentation for further details.
42+
Python还有其他的模块可用来处理多种归档格式(比如tarfile, zipfile, gzip, bz2)的底层细节。
43+
不过,如果你仅仅只是要创建或提取某个归档,就没有必要使用底层库了。
44+
可以直接使用 ``shutil`` 中的这些高层函数。
45+
46+
这些函数还有很多其他选项,用于日志打印、预检、文件权限等等。
47+
参考 `shutil文档 <https://docs.python.org/3/library/shutil.html>`_

0 commit comments

Comments
 (0)