Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87710
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; '---------': 0.07; 'os.path': 0.09; '--------': 0.10; "'w')": 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'how,': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'please?': 0.24; 'script': 0.25; 'extension': 0.26; 'header:In-Reply-To:1': 0.27; 'skip:g 30': 0.30; "skip:' 10": 0.31; 'file': 0.32; 'run': 0.32; 'received:84': 0.35; 'but': 0.35; 'add': 0.35; 'method': 0.36; 'subject:?': 0.36; 'skip:o 20': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'you.': 0.62; 'more': 0.64; 'subject:add': 0.91 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=A5niPsmG c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=mlFM_a_ONtUA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=G0CfL_yH8SRrSe4BwLsA:9 a=QEXdDO2ut3YA:10 |
| X-AUTH | mrabarnett@:2500 |
| Date | Wed, 18 Mar 2015 23:58:03 +0000 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: how should i add extension and unzip again? |
| References | <7604e075-4d1f-4e53-b1f6-28696044e2bd@googlegroups.com> |
| In-Reply-To | <7604e075-4d1f-4e53-b1f6-28696044e2bd@googlegroups.com> |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14.1426723088.10327.python-list@python.org> (permalink) |
| Lines | 27 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1426723088 news.xs4all.nl 2856 [2001:888:2000:d::a6]:34458 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:87710 |
Show key headers only | View raw
On 2015-03-18 23:22, PK Khatri wrote:
> This script untars .gz file to file without extension
> --------
> import gzip
> import glob
> import os.path
> import tarfile
>
> source_dir = "C:\\TEST"
> dest_dir = "C:\\TEST"
> for src_name in glob.glob(os.path.join(source_dir, '*.gz')):
> base = os.path.basename(src_name)
> dest_name = os.path.join(dest_dir, base[:-3])
> with tarfile.open(src_name, 'r') as infile:
> with open(dest_name, 'w') as outfile:
> for line in infile:
> outfile.write(str(line))
> ---------
> but i know it is a compressed file so I need to add extension .zip to it and run untar/unzip one more time so it will fully unzip to folders and files, not sure how, can someone help please?
> Thank you.
>
There's a method called 'extractall':
with tarfile.open(src_name, 'r') as infile:
infile.extractall(dest_dir)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how should i add extension and unzip again? PK Khatri <piseema@gmail.com> - 2015-03-18 16:22 -0700
Re: how should i add extension and unzip again? MRAB <python@mrabarnett.plus.com> - 2015-03-18 23:58 +0000
Re: how should i add extension and unzip again? PK Khatri <piseema@gmail.com> - 2015-03-18 20:28 -0700
csiph-web