[Tutor] need an explanation

Matthew Ngaha chigga101 at gmail.com
Thu Oct 11 21:24:30 CEST 2012

i need help on 2 topics.

1) can someone please tell me what sys is doing, and why its using weird

if __name__ == "__main__":

is sys able to call methods? if so why does it need indexing if it uses * .

2) also i need help with zipfiles. these 2 functions are related in the
same class.

def __init__(self):
    self.zipping_directory = "unzipped-{}".format(filename)

def _full_filename(self, filename):
        return os.path.join(self.zipping_directory, filename)

def zip_files(self):
        file = zipfile.ZipFile(self.filename, 'w')
        for filename in os.listdir(self.zipping_directory):
            file.write(self._full_filename(filename), filename)

the main thing i need help with is the last line. the zip file is writing
to a file but why does it use the same argument twice? the for loop above
that line returns the file from the zipping directory, which is the 2nd
argument on file.write? But the 1st argument is using that same file
because that is the file returned from the def _full_filename(self,
filename): method. so please can someone tell me why it uses the same file
argument twice in its write method?

thanks for your time
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121011/a35fe34f/attachment.html>

More information about the Tutor mailing list