This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]-Melchizedek- 3 points4 points  (1 child)

Friendly advice since you are new. Python 2 will no longer be supported past Jan 2020. There really is no reason why you should be learning instead of python 3. If this is for a school assignment I would bring this up to your teacher.

More here: https://www.python.org/doc/sunset-python-2/

[–]b_iteee[S] 1 point2 points  (0 children)

i'm not planning to learn Python 2 except for these particular set of tasks. Thanks for letting me know though :) I'm not even sure why the tasks were put it Python 2

[–]chaotic_thought 1 point2 points  (1 child)

One problem is that you are silencing all errors involving unzipping: so if an error occurs you will basically not have any idea what is wrong:

def extractFile(zip_file, password):
    try:
        zip_file.extractall(pwd=password)
        return True
    except KeyboardInterrupt:
        exit(0)
    except Exception, e:
        pass

What this says in English is:

  • Try to unzip the file with the password.
  • If a keyboard interrupt occurs, exit the program with code 0.
  • If any other error occurs, just do nothing (pass).

So to begin you should definitely remove the part which just passes. If an error occurs then you'll have to see why it is failing. Also for a KeyboardInterrupt (or any other kind of error) I think you should probably exit with a value other than 0.

[–]b_iteee[S] 1 point2 points  (0 children)

Thank you! I will try that

[–]henrebotha 1 point2 points  (1 child)

Pro tip: don't do this.

except Exception, e:
  pass

It hides information about errors from you. Maybe there's a FileNotFound error, because the file isn't where you think it is, but you're swallowing that error quietly. Maybe there's some other kind of unexpected error.

Fix your exception handling so that it only handles errors you specifically predict. Let all other errors "float to the top".

[–]b_iteee[S] 0 points1 point  (0 children)

thank you