[Python] python 读取tar文件 →→→→→进入此内容的聊天室

来自 , 2019-05-25, 写在 Python, 查看 118 次.
URL http://www.code666.cn/view/8744cf92
  1. #!/usr/bin/env python
  2. # [SNIPPET_NAME: Open a tar file]
  3. # [SNIPPET_CATEGORIES: tarfile]
  4. # [SNIPPET_DESCRIPTION: Open's a tar file and list the entries]
  5. # [SNIPPET_AUTHOR: Tim Voet <tim.voet@gmail.com>]
  6. # [SNIPPET_DOCS: http://docs.python.org/library/tarfile.html#module-tarfile]
  7. # [SNIPPET_LICENSE: GPL]
  8.  
  9. import tarfile
  10. import os
  11. import sys
  12.  
  13. user =  os.getenv('USERNAME')
  14.  
  15.  
  16. filename = '/home/%s/tmp.tgz' % user
  17.  
  18. print 'about to open %s' % filename
  19. mode = 'r:gz'
  20.  
  21. if os.path.isfile( filename ) and tarfile.is_tarfile( filename ):
  22.     tf = tarfile.open( filename, mode )
  23.     tf.list()
  24.     tf.close()
  25. #//python/2376

回复 "python 读取tar文件"

这儿你可以回复上面这条便签

captcha