国产gaysexchina男同gay,japanrcep老熟妇乱子伦视频,吃奶呻吟打开双腿做受动态图,成人色网站,国产av一区二区三区最新精品

13.8 創(chuàng)建和解壓壓縮文件

2018-02-24 15:27 更新

問題

You need to create or unpack archives in common formats (e.g., .tar, .tgz, or .zip).

解決方案

The shutil module has two functions—make_archive() and unpack_archive()—thatdo exactly what you want. For example:

>>> import shutil
>>> shutil.unpack_archive('Python-3.3.0.tgz')

>>> shutil.make_archive('py33','zip','Python-3.3.0')
'/Users/beazley/Downloads/py33.zip'
>>>

The second argument to make_archive() is the desired output format. To get a list ofsupported archive formats, use get_archive_formats(). For example:

>>> shutil.get_archive_formats()
[('bztar', "bzip2'ed tar-file"), ('gztar', "gzip'ed tar-file"),
 ('tar', 'uncompressed tar file'), ('zip', 'ZIP file')]
>>>

討論

Python has other library modules for dealing with the low-level details of various archiveformats (e.g., tarfile, zipfile, gzip, bz2, etc.). However, if all you’re trying to do ismake or extract an archive, there’s really no need to go so low level. You can just usethese high-level functions in shutil instead.The functions have a variety of additional options for logging, dryruns, file permissions,and so forth. Consult the shutil library documentation for further details.

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)