在python中打开.tar.gz档案 [英] open .tar.gz archives in python

查看:311
本文介绍了在python中打开.tar.gz档案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

,这对用Python编码的行有问题:

,i've got an issue with this pair of lines, coded in Python:

#File name spacchetta_N_zip.py

import tarfile
import gzip
    with tarfile.TarFile.open(i, 'r:gz') as tarredgzippedFile:
                        tarredgzippedFile.extractall(cartella)

我确定我正在打开.tar.gz存档.

I'm sure i'm opening a .tar.gz archive.

我真的不知道出什么问题了,我已经上网冲浪了,这可以工作...但是我遇到了这个错误:

I really don't know what's wrong, i've surfed the web and this would work... but i got this error:

File "spacchetta_N_zip.py", line 70, in Spacchetta
    with tarfile.TarFile.open(i, 'r:gz') as tarredgzippedFile:
  File "/usr/lib/python2.7/tarfile.py", line 1678, in open
    return func(name, filemode, fileobj, **kwargs)
  File "/usr/lib/python2.7/tarfile.py", line 1729, in gzopen
    raise ReadError("not a gzip file")
tarfile.ReadError: not a gzip file

请帮助我

推荐答案

您可以尝试一下.

tar = tarfile.open("FILE_NAME.tar.gz")
tar.extractall()
tar.close()

我正在使用centos,它正在工作.希望这会有所帮助.

I'm using centos and it's work. Hope this will help.

这篇关于在python中打开.tar.gz档案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆