python 读取tar文件
#!/usr/bin/env python # [代码名字: Open a tar file] # [代码分类: tarfile] # [代码描述: Open's a tar file and list the entries] # [代码作者: Tim Voet <tim.voet@gmail.com>] # [SNIPPET_DOCS: http://docs.python.org/library/tarfile.html#module-tarfile] # [代码协议: GPL] import tarfile import os import sys user = os.getenv('USERNAME') filename = '/home/%s/tmp.tgz' % user print 'about to open %s' % filename mode = 'r:gz' if os.path.isfile( filename ) and tarfile.is_tarfile( filename ): tf = tarfile.open( filename, mode ) tf.list() tf.close()