On 11/10/2012 20:24, Matthew Ngaha wrote:
i need help on 2 topics.

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

sys isn't doing anything and the weird indexing is called slicing.


if __name__ == "__main__":
     A_Class(*sys.argv[1:4]).A_Class_Method()

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

sys isn't calling anything. The second, third and fourth items from sys.argv are being used via slicing to create A_Class and then A_Class_Method is called.



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

Obviously a Monty Python fan as I see 3 methods :)


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

Where did filename appear from above?


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

def zip_files(self):
         file = zipfile.ZipFile(self.filename, 'w')

Where is self.filename set up?

         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?

I suggest that you show us some real code that will run with some print statements in appropriate places to show us what is happening. That way you may well be able to answer your own questions and learn at the same time.


thanks for your time



_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



--
Cheers.

Mark Lawrence.

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to