[Tutor] memory error files over 100MB

Harris, Sarah L sarah.l.harris at jpl.nasa.gov
Tue Mar 10 16:45:01 CET 2009


That looks better, thank you.
However I still have a memory error when I try to run it on three or more files that are over 100 MB?

import zipfile, glob, os
from os.path import isfile
zipnames=filter(isfile, glob.glob('*.zip'))
for zipname in zipnames:
        zf=zipfile.ZipFile(zipname, 'r')
        for zfilename in zf.namelist():
            newFile=open(zfilename, 'wb')
            newFile.write(zf.read(zfilename))
            newFile.close()
        zf.close()
________________________________________
From: Moos Heintzen [iwasroot at gmail.com]
Sent: Monday, March 09, 2009 9:02 PM
To: Harris, Sarah L
Cc: tutor at python.org
Subject: Re: [Tutor] memory error

On Fri, Mar 6, 2009 at 5:03 PM, Harris, Sarah L
<sarah.l.harris at jpl.nasa.gov> wrote:

> fname=filter(isfile, glob.glob('*.zip'))
> for fname in fname:
>     zipnames=filter(isfile, glob.glob('*.zip'))
>     for zipname in zipnames:
>         ...

It looks you're using an unnecessary extra loop.
Aren't the contents of fname similar to zipnames?

I tried it with one loop (for zipname in zipnames:) and it worked.

P.S. You're at jpl? That's awesome! I was looking at internships they
have few days ago.


More information about the Tutor mailing list