Ok trying to work with zipFile library how do you flatten the file hierarchy
what works

zipFile = zipfile.ZipFile(imgSetup[0]+'/'+zipName, 'w') 
for picId, pathname in enumerate(pic_list):
       if start <= picId and picId <= end:
            zip.write(filedir+'/'+pathname)
    zip.close()

what i am trying

zipFile = zipfile.ZipFile(imgSetup[0]+'/'+zipName, 'w')
    for picId, pathname in enumerate(pic_list):
       if start <= picId and picId <= end:
            fileObj = open (filedir+'/'+pathname)
            zip.write(fileObj)
    zip.close()

Am i on the right track if so how do I make it work

Recommended Answers

All 4 Replies

I don't think so : zip.write waits for a file NAME and you pass a file OBJECT.
I think this may be done by using the second argument of zip.write :

zip.write(filename, arcname=None, compress_type=None)
# filename = the file you want to archive
# arcname the name you give to the file in the archive (if None, it will be filename)
# compress_type = zipfile.ZIP_STORED or zipfile.ZIP_DEFLATED)

Thanks for the help

what would conflict to cause

AttributeError: 'builtin_function_or_method' object has no attribute 'write'

zipFile = zipfile.ZipFile(picSetup[0]+'/'+zipName, 'w')
    for picId, pathname in enumerate(picSetup):
       if start <= picId and picId <= end:
          zip.write(filedir+'/'+pathname, zipFile, compress_type=None)
    zip.close()

my includes

import pickle
import os
import Tkinter as tk
import tkFileDialog
import tkMessageBox
from Tkinter import *
from PIL import ImageTk, Image
import zipfile

Sorry, I answered too fast :

zipFile.write(filedir+'/'+pathname, zipFile, compress_type=None)

zip is not defined in your program, so it refers to the builtdin function which has nothing to do with zip archives...
The object you want to write in is the onr you defined here :

zipFile = zipfile.ZipFile(picSetup[0]+'/'+zipName, 'w')

thanks
I found it yesterday (felt like an idiot)

Solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.