Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)
edited by

This is my code:

import zipfile

try:

    with zipfile.ZipFile("daysv2.zip") as file:

        file.extractall(pwd='abc123')

except Exception as e:

    print(e)

else:

    print("Extraction was successful")

I want to change such that the user can type the directory and his/her password? I also want to fix this error of

PWD: expected bytes, got st

1 Answer

0 votes
by (36.8k points)
edited by

The pwd must be a bytes object, which is written/indicated such as b'abc123'. Or more generically:

bytes('abc123', 'UTF-8') # For UTF-8 encoded string -> bytes

If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch 

Browse Categories

...