On 24 September 2012 03:00, Gregory Lund <gnj091...@gmail.com> wrote:
> >>> > You're trying to open the directory as if it were a zipfile. You > should > >>> > pass in the path to a zipfile not to a folder. > >>> > >>> Agreed, but how do I do that "pass in the path to a zipfile'? > >>> Using an if statement I presume? > >>> > >>> > > > >>> > >>> > > I guess my first issue is to resolve the 'Permission denied' > problem. > >>> > > And, I know I need an 'if' statement, somehow... > >>> > > >>> Yes, the permission denied problem seems to be the first real > >>> obstacle, but I can't figure it out. > >>> I tried searching online but everything I found to try, didn't work. > >> > >> > >> The permission error is because you are trying to open a folder as if it > >> were a file. The operating system does not give you permission to do > this > >> because it is a nonsensical operation. > >> > >>> > Remove the folder paths from the list of paths. > >>> > >>> How can I remove the folder paths from the list of paths? > >> > >> > >> You can do it with a list comprehension: > >> > >> import os.path > >> paths = [p for p in paths if os.path.isdir(p)] > > > > > > Sorry that should be (note the 'not'): > > paths = [p for p in paths if not os.path.isdir(p)] > > > Ok, but where do I put that? > Sorry Oscar, I don't know where to put it, nor do I know how to use > 'paths' once I do that. > > I was trying this prior to getting your email about paths...(I put > this after z.close() > > for item in zipContents: > if item(-4) == ('.zip'): > That should be: if item[-4:] == '.zip' but a better way to do that is: if item.endswith('.zip') x = zipfile.Zipfile(item,'r') > x.extractall() > x.close() > > but, I kept getting a "TypeError: 'str' object is not callable" error. > > then I tried > > for item in zipContents: > if item.lower() .endswith(".zip"): > Ok that's better. > item.extractall() > item.close() > > but got a " item.extractall() > AttributeError: 'str' object has no attribute 'extractall'" error > item is a string object. You need to use that string to create a ZipFile object and then call extractall() on the ZipFile object (the way you did in your original post in this thread). Oscar
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor