+ 4
OfficialAz3[ACTIVEn't]:Rhythm Gamer|Coder|Musician you are not following th correct API for the ZipFile class. In the constructor, it takes 1 parameter - the zip file name (eg. somefile.zip) - and 1 optional parameter - the mode (either 'r' for reading or 'w' for writing). To write to a zipfile, create an object with the mode 'w' zipfileobj = ZipFile("hello.zip", "w") Then you the write method on it which takes 1 parameter- the path of the file as a string (if the file does not exist, you can make one using the normal open() function) zipfileobj.write("image.jpg") To read, create an object with mode "r". Then use the read method on it to read a specific file. The read method returns a normal file object in Python in read mode. zipfile = ZipFile('new.zip', 'r') file = zipfile.read("hello.py") print(file.read()) Read the docs https://docs.python.org/3/library/zipfile.html#zipfile-objects or this https://www.geeksforgeeks.org/working-zip-files-python/
6th Aug 2020, 6:50 AM
XXX
XXX - avatar
+ 1
Use open() which have syntax as f=open(filename) where f is file handler
6th Aug 2020, 6:00 AM
Rajneesh Singh
Rajneesh Singh - avatar
+ 1
OfficialAz3[ACTIVEn't]:Rhythm Gamer|Coder|Musician yes. open(filename, 'rb') will obtain the contents of the file in the form of bytes. In the same way to can write bytes into file by 'wb'
6th Aug 2020, 6:05 AM
XXX
XXX - avatar
0
OfficialAz3[ACTIVEn't]:Rhythm Gamer|Coder|Musician try to use pickle module that may help
6th Aug 2020, 6:19 AM
Rajneesh Singh
Rajneesh Singh - avatar