2.0c1 zipfile problem

Steve Holden sholden at holdenweb.com
Thu Oct 12 10:18:32 EDT 2000


Jeff Buaer was kind enough to point out that I omitted the parens
after z.close, so I wasn't closing the archive correctly.

Well, duuhh!  Everything's fine now -- thanks, Jeff.

regards
 Steve

Steve Holden wrote:
> 
> The zipfile library in 2.0 came along at just the right time to
> solve a client's problem.  However, my dumbass attempts to use
> it are meeting with no success.
> 
> Can someone who knows this library tell me why the program below
> creates an archive about which WinZip 7.0 says:
> 
> Cannot open this file: it does not appear to be a valid archive"
> 
> The zipfile library also gives me a BadZipFile exception if I try
> to read the file back.
> 
> If it makes a difference (byte ordering?) I am running this on a
> SPARCstation under Red Hat Linux 5.2.  IF I can get verification
> that the code seems correct I will report a bug, but at present I
> suspect programmer error.
> 
> Does this program work on other architectures, or what have I done wrong?
> 
> regards
>  Steve
> -----------------------------------------------------------------
> import zipfile
> import os.path
> import sys
> #
> # NOTE: requires binascii module from python 2
> #
> def createzip(name, ext):
>     target = name+".zip"
>     if os.path.exists(target):
>         print target, "exists"
>         return
>     z = zipfile.ZipFile(target, mode="w")
>     z.write(name+"."+ext)
>     z.close
>     print target, "created"
> 
> createzip(sys.argv[1], sys.argv[2])
> 
> --
> Helping people meet their information needs with training and technology.
> 703 967 0887      sholden at bellatlantic.net      http://www.holdenweb.com/

-- 
Helping people meet their information needs with training and technology.
703 967 0887      sholden at bellatlantic.net      http://www.holdenweb.com/





More information about the Python-list mailing list