参考:

https://docs.python.org/2/library/tarfile.html

http://www.jianshu.com/p/bbad16822eab

#解压文件
tarfile.open(filepath, 'r:gz').extractall(inception_pretrain_model_dir)

python中os.walk的用法

如下的文件结构:

 a ->   b   ->   .txt,  .txt
             c   ->   .txt
             d   ->
           .txt
           .txt
for (root, dirs, files) in os.walk('a'):
    #第一次运行时,当前遍历目录为 a
    所以 root == 'a'
         dirs == [ 'b', 'c', 'd']
         files == [ '4.txt', '5.txt']

    。。。

    # 接着遍历 dirs 中的每一个目录
    b:  root  = 'a\\b'
        dirs  = []
        files = [ '1.txt', '2.txt']

    # dirs为空,返回
    # 遍历c
    c:  root  = 'a\\c'
        dirs  = []
        files = [ '3.txt' ]

    PS : 如果想获取文件的全路径,只需要
    for f in files:
        path = os.path.join(root,f)

    # 遍历d
    d:  root  = 'a\\b'
        dirs  = []
        files = []

    遍历完毕,退出循环

tarfile — Read and write tar archive files的更多相关文章

  1. How to append files to a .tar archive using Apache Commons Compress?(转)

    I created a copy of the tar archive and copied to entire content to it. Then I delete the old tar ar ...

  2. tar: This does not look like a tar archive tar: Skipping to next header tar: Exiting with failure status due to previous errors

    解压一个.tar.zip文件时报错 tar -zxvf bcl2fastq2-v2---linux-x86-.zip tar: This does not look like a tar archiv ...

  3. 如何解压POSIX tar archive文件

    下载了一个xxx.gz的文件,使用x xxx.gz(zsh的x插件,十分之好用,再也不用担心tar后面该加哪些参数了)的命令解压,然后出现了一个文件,本以为解压后是一个文件夹:然后一脸蒙逼~ 突然又想 ...

  4. Linux tar This does not look like a tar archive

    由于昨天公司内网服务器坏了,所以急需搭建新的Linux环境. 在安装maven时,使用tar 命令解压maven.tar.gz出现: tar :This does not look like a ta ...

  5. WebJars are client-side web libraries (e.g. jQuery & Bootstrap) packaged into JAR (Java Archive) files

    webjars网站https://www.webjars.org/,这里将很多的东西都打包成了jar包,想要用什么只需要导入相关的依赖就可以了. 比如springboot会用到jquery,webja ...

  6. Python教程大纲

    缘起:最近想在部门推Python语言,写这个blog主要就是个教程大纲,之前先列出一些资源:Python历史:http://www.docin.com/p-53019548.html          ...

  7. The Python Standard Library

    The Python Standard Library¶ While The Python Language Reference describes the exact syntax and sema ...

  8. Modules you should know in Python Libray

    前两天被问到常用的python lib和module有哪些?最常用的那几个,其他的一下子竟然回答不上.想想也是,一般情况下,遇到一个问题,在网上一搜,顺着线索找到可用的例子,然后基本没有怎么深究.结果 ...

  9. [Linux命令]tar命令

    tar 命令的解释: tar(bsdtar): manipulate archive files First option must be a mode specifier: -c Create -r ...

随机推荐

  1. P标签莫名有了margin-top值的原因

    p标签默认 -webkit-margin-after: 1em; -webkit-margin-before: 1em;元素上下边距数值为1倍字体高度 设置-webkit-margin-after: ...

  2. Linux pwn入门教程——CTF比赛

    Linux pwn入门教程(1)——栈溢出基础 from:https://zhuanlan.zhihu.com/p/38985585   0x00 函数的进入与返回 要想理解栈溢出,首先必须理解在汇编 ...

  3. Qt中漂亮的几款QSS

    /* === Shared === */QStackedWidget, QLabel, QPushButton, QRadioButton, QCheckBox, QGroupBox, QStatus ...

  4. python3使用requests模块完成get/post/代理/自定义header/自定义Cookie

    一.背景说明 http请求的难易对一门语言来说是很重要的而且是越来越重要,但对于python一是urllib一些写法不太符合人的思维习惯文档也相当难看,二是在python2.x和python3.x中写 ...

  5. windows配置教程

    1.卸载预装软件 2.卸载非安装的预装软件 有些软件被改成了“绿色版”软件不能通过软件列表卸载,一般在C:\Program Files (x86)目录下 可以直接删除其文件夹,如果提示文件夹无法删除则 ...

  6. git上传新建项目

    新建立本地项目,现在需要上传到git.对上传过程归纳如下: 一 在gitlab中新建项目:如下图所示: 二,新建后获取url地址,在本地打开gitbash,根据url把git上的项目clone到本地: ...

  7. win10系统office2010每次打开总是出现配置进度

  8. Intellij下Jquery中文乱码

    今天在用Jquery+Ajax实现检查用户名是否可用的功能时,意外的发生了乱码,谷歌了很久后终于找到了解决办法: 把js文件复制一份在桌面 用记事本打开,另存为UTF-8格式 复制粘贴回去,覆盖之前的 ...

  9. es6新增的math函数有哪些

    Math.trunc():用于去除一个数的小数部分,返回整数部分. Math.sign():用来判断一个数到底是正数.负数.还是零. Math.cbrt():用于计算一个数的立方根. Math.hyp ...

  10. 读书笔记 C# 接口之浅析

    一.接口可以包含 属性.方法.事件和索引器: 二.接口不能被实例化: 三.一个类可以继承多个接口: 四.接口不能包含方法的实现: 五.继承接口的类必须实现接口中所有成员: 六.显式实现接口的成员,不能 ...