Sample code for 30+ languages & platforms
Chilkat2-Python

Unzip Text File to String

See more Zip Examples

Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to a string variable.

Chilkat Chilkat2-Python Downloads

Chilkat2-Python
import sys
import chilkat2

success = False

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

zip = chilkat2.Zip()

success = zip.OpenZip("qa_data/zips/EC16100.zip")
if (success == False):
    print(zip.LastErrorText)
    sys.exit()

# Get the 1st file in the .zip
entry = chilkat2.ZipEntry()
success = zip.EntryAt(0,entry)
if (success == False):
    print(zip.LastErrorText)
    sys.exit()

fileContents = entry.UnzipToString(0,"utf-8")
print(fileContents)