ajkey94 ajkey94 - 3 months ago 29
Python Question

How do I read text files within a zip file?

So say I have a zip file named "files.zip"
it contains



other words

How do I tell python to open and read the text1.txt file? I know that usually to open a text file outside of a zip file I would just do this:

file = open('text1.txt','r')


You can use the zipfile module like so:

zip = zipfile.ZipFile('test.zip')
file = zip.read('text1.txt')

Don't forget to import zipfile module: import zipfile