[Tutor] Unzip a zipfile, then unzip the zipfiles within the original zip

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Aug 7 20:10:38 CEST 2012


On 07/08/2012 18:10, Gregory Lund wrote:
> # neophyte .py/pyTutor user.
> # I am also a university GIS lecturer. My students submit their lab
> assignments (zipped up into one zipfile) to a depository, which I
> download as a single zip containing all 40 students' zipfiles.
> # Goal: unzip a zipfile of student zipfiles and then unzip each
> students' zipfile ( to prevent me from having to unzip each students'
> zipfile by hand. )
> # eventually I'll turn this into a tool in ArcGIS, that will grade
> some of their assignment, but for now, just want to get these extract
> processes running in python.
>
> # using (and want to use) 2.6 because I'm working with ArcGIS
> # this is what I've got thus far:
>
> #1 Unzip a single starting zipfile "initial_Zipfile" (that contains a
> series of 40 individual zipfiles) into a single folder named whatever
> it was originally named.
>
> #2 Unzip all of the zipfiles within the 'initial_Zipfile' into their own folder.
>
> ## Actual  Code:
>
> import zipfile, arcpy, os.path, os
>
> #1 Defining a function to Unzip the initial (.zip) folder. (this worked fine)
>
> def unzip_Orig(oZ):
>      z = zipfile.ZipFile(oZ)
>      z.extractall()
>      return
>
> q = "unzip_Unzip_Data_Test.zip"
> unzip_Orig(q)
>
> #2 my attempts to unzip each zipfile within the new folder below
> (failed thus far)
>
> mywd = os.getcwd()
> zipList = os.listdir(mywd)
> print zipList  #this didn't work, it printed the directory of where
> the .py was stored.

Given the help below for the two os functions you've called, what did 
you expect it to do?

 >>> help(os.getcwd)
Help on built-in function getcwd in module nt:

getcwd(...)
     getcwd() -> path

     Return a string representing the current working directory.

 >>> help(os.listdir)
Help on built-in function listdir in module nt:

listdir(...)
     listdir(path) -> list_of_strings

     Return a list containing the names of the entries in the directory.

         path: path of directory to list

     The list is in arbitrary order.  It does not include the special
     entries '.' and '..' even if they are present in the directory.

> #Zipfile.printdir() # returned "'Zipfile' is not defined.

True indeed, did you mean this to be zipList or what?

>
> #thoughts?

Your assignment for tonight is to go back to the drawing board, let's 
face it we wouldn't write code for your students :)

>
> # Thanks
> # Greg
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

-- 
Cheers.

Mark Lawrence.



More information about the Tutor mailing list