it program printzip.py, print contains of zip file. suppose, zip contains multiple text files, print name of text files. okay it.
import zipfile zf = zipfile.zipfile('desktop.zip', 'r') print (zf.namelist()) output :- test1.txt, test2.txt
but, question is, how can take text files further analysis. like, want count line, words, characters of text files (i can perform operations).
but, question how take output variable input of further work. don't know name of text files. may single or multiples.
as example, want take test1.txt , test2.txt input future operations.
also, did not know zip file contains 2 text files before running printzip.py program. there library multiprocessing work? thanks.
zf.namelist() returns python list of names of files in archive. can use for loop each name list , in loop use zf.read() bytes of each file. example, print name list, , name & uncompressed size of each file in archive.
import zipfile zf = zipfile.zipfile('desktop.zip', 'r') fnames = zf.namelist() print(fnames) fname in fnames: data = zf.read(fname) print(fname, len(data)) #... other text processing here zf.close()
Comments
Post a Comment