Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.058 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'memory.': 0.07; 'extracted': 0.09; 'python': 0.11; '2.7': 0.14; 'file-like': 0.16; 'read()': 0.16; 'subject:item': 0.16; 'tags.': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'code.': 0.18; 'work,': 0.20; 'header:User- Agent:1': 0.23; 'file.': 0.24; 'help!': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'xml': 0.29; "doesn't": 0.30; 'to?': 0.30; 'coded': 0.31; 'extract': 0.31; 'object.': 0.31; 'file': 0.32; 'open': 0.33; 'up.': 0.33; 'url:python': 0.33; 'maybe': 0.34; 'curious': 0.36; 'method': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'so,': 0.37; 'somebody': 0.38; 'url:library': 0.38; 'to:addr :python-list': 0.38; 'files': 0.38; 'pm,': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; 'back': 0.62; "you've": 0.63; 'zip': 0.64; 'charset:windows-1252': 0.65; 'here': 0.66; 'received:74.208': 0.68; 'containing': 0.69; 'around,': 0.84; 'url:open': 0.95 Date: Wed, 06 May 2015 16:38:21 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: extracting zip item to in-memory References: <95e1cce0-18ed-477a-a265-3256b7bcb25a@googlegroups.com> In-Reply-To: <95e1cce0-18ed-477a-a265-3256b7bcb25a@googlegroups.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:9bpaB5BJzXm0Ggj4Oa6Wk/gK11Ey+MxTBzU/BXrrigBbRDLoV8W rsXLwXOz8sHsft85DsZUhV6g577S8Z1W7JjngaHj2O5YXYT2BCgPRbG/FQw57PTq+G2PXS5 5NRvl1R6VDfXghAh3qMquAzwrUPn46QRtgNx8ShIbXklXu3LDdkpS+/KtDaR2Kq1ylmjzzX yISGq7FXIQj1EmRw8O+2g== X-UI-Out-Filterresults: notjunk:1; X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430944712 news.xs4all.nl 2831 [2001:888:2000:d::a6]:55362 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3614 X-Received-Body-CRC: 1004649860 Xref: csiph.com comp.lang.python:90074 On 05/06/2015 04:27 PM, noydb wrote: > I have a zip file containing several files and I want to extract out just the .xml file. I have that code. Curious if this xml file can be extracted into memory. If so, how to? I only need to move the file around, and maybe read some tags. > > Thanks for any help! > > python 2.7 > See https://docs.python.org/2.7/library/zipfile.html#zipfile.ZipFile.open To open a particular member and get back a file-like object. Once you have that, you can use the read() method of that object. Once you've coded this, if it doesn't work, post what you've got with a description of what doesn't work, and somebody here will be able to fix it up. -- DaveA