MARCUS NG wrote:
Hey all,
I have been searching online for ways to copy a zip file to a destination and extract the zip file with python.
Currently nothing works due to my limited understanding.
I am wondering if my syntax is wrong or am I missing anything?
the code is as such. also if there is a better code, I am definitely open to it. If it is good, can you also explain steps?

It is probably good if you went through some beginner python tutorials...

anyways, there are many reasons why your script doesn't work...


import shutil, zipfile
shutil.copyfile('C:\Users\blueman\Desktop\myTest1..0.zip', 'C:\Users\blueman\Desktop\allFiles')

zipfilepath='C:\Users\blueman\Desktop\allFiles\myTest1.0.zip'
extractiondir='C:\Users\blueman\Desktop\allFiles\test'


note that you're defining 'extract' with two required arguments here:

def extract(zipfilepath, extractiondir):

you're calling a module, which doesn't make sense. What you want is to call zipfile.ZipFile(zipfilepath)

    zip = zipfile(zipfilepath)
    zip.extractall(path=extractiondir)
    print 'it works'


remember that you defined 'extract' with two required arguments earlier? Here you're calling 'extract' without any arguments. You should pass two arguments to extract: extract(something, something_else)

extract()

###########
thank you so much for your time and help in advance!!!


,
Marcus


------------------------------------------------------------------------

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

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

Reply via email to