您现在的位置是:课程教程文章
python如何生成tar文件内容
2023-12-18 22:40课程教程文章 人已围观
-
Python入门到精通/Python/软件测试
Python入门到精通/Python/软件测试课程咨询qq:2681268608 微信:13691729932 课程内容包括Python基础语法、数据类型和类型... -
Uzdil Python语言基础【维吾尔语】
Uzdil Python语言基础【维吾尔语】课程简介 本课程为Python入门阶段的学员准备,零基础学起来也完全没有压力。... -
机器学习应用
机器学习应用主要内容 主要介绍机器学习开发及应用的基础知识、流程、典型而常用的模型... -
软件测试基础知识
软件测试基础知识学习内容: 1.软件测试概述 2.软件测试目的和原则 3.软件缺陷以及影响 4.软件测...
tarfile包中的.open(name, mode)方法能够以mode指定的方式打开name压缩文件,并返回一个TarFile类对象。调用TarFile对象的extractall(path)方法可以将tar文档解压到path指定的位置。
import tarfile tar = tarfile.open( '*.tar.gz', mode = "r:gz") #"r:gz"表示 open for reading with gzip compression tar.extractall(path='temp') ### 将tar.gz文件解压到temp文件夹下 tar.close()
open返回的对象不但可以用来读文档数据('r': reading),还可以写('w': writing),附加('a': appending)。
相关推荐:《Python教程》
如下是mode取值所对应的含义:
'r' or 'r:*' open for reading with transparent compression 'r:' open for reading exclusively uncompressed 'r:gz' open for reading with gzip compression 'r:bz2' open for reading with bzip2 compression 'r:xz' open for reading with lzma compression 'a' or 'a:' open for appending, creating the file if necessary 'w' or 'w:' open for writing without compression 'w:gz' open for writing with gzip compression 'w:bz2' open for writing with bzip2 compression 'w:xz' open for writing with lzma compression 'x' or 'x:' create a tarfile exclusively without compression, raise an exception if the file is already created 'x:gz' create a gzip compressed tarfile, raise an exception if the file is already created 'x:bz2' create a bzip2 compressed tarfile, raise an exception if the file is already created 'x:xz' create an lzma compressed tarfile, raise an exception if the file is already created 'r|*' open a stream of tar blocks with transparent compression 'r|' open an uncompressed stream of tar blocks for reading 'r|gz' open a gzip compressed stream of tar blocks 'r|bz2' open a bzip2 compressed stream of tar blocks 'r|xz' open an lzma compressed stream of tar blocks 'w|' open an uncompressed stream for writing 'w|gz' open a gzip compressed stream for writing 'w|bz2' open a bzip2 compressed stream for writing 'w|xz' open an lzma compressed stream for writing课程教程:python如何生成tar文件内容
上一篇:python的函数有什么作用
下一篇:没有了