Start New Discussion within our Software Development Community

Hi,

I am zipping a folder and an error occurred in below code which says :
==> AttributeError: 'builtin_function_or_method' object has no attribute 'tell'

zipfile.py:

def write(self, filename, arcname=None, compress_type=None):
...
zinfo.header_offset = self.fp.tell()    # Start of header bytes
...
...

FYI:I have tried using "from zipfile import *" instead of "import zipfile", but of no avail.

What is causing this problem?

Regards,
Zia


My code to zip a folder:

import zipfile  [B]## i've tried with "from zipfile import *"[/B]
import os

def main():
    zip = "help3.zip"
    directory = "C:\MYDIR"
    toZip(directory)


def toZip(directory):
    zippedHelp = zipfile.ZipFile(zip, "w", compression=zipfile.ZIP_DEFLATED )

    zipfile.debug = 3
    list = os.listdir(directory)

    for entity in list:
        each = os.path.join(directory,entity)

        if os.path.isfile(each):
            print each
            print os.path.basename(each)
            zippedHelp.write(each, os.path.basename(each), zipfile.ZIP_DEFLATED)
        else:
            addFolderToZip(zippedHelp,entity)

    zippedHelp.close()

def addFolderToZip(zippedHelp,folder):

    for file in folder:
            if os.path.isfile(file):
                zippedHelp.write(file, os.path.basename(file), zipfile.ZIP_DEFLATED)
            elif os.path.isdir(file):
                addFolderToZip(zippedHelp,file)

main()

you're going to kick yourself if you see this but the app is right except for one part, see you pass the directory path which is awesome but what about the zip filename.

zippedHelp = zipfile.ZipFile(zip, "w", compression=zipfile.ZIP_DEFLATED )

see you using there but it hasn't been declared anywhere in that definition.
so when you call the toZip function do it like this:

toZip(zip, directory)

and receive it like such:

def toZip(zip, directory):

that should do the trick

This article has been dead for over six months. Start a new discussion instead.