How do you read a file inside a zip file as text, not bytes?

前端 未结 4 800
我寻月下人不归
我寻月下人不归 2020-12-09 02:03

A simple program for reading a CSV file inside a zip file works in Python 2.7, but not in Python 3.2

$ cat test_zip_file_py3k.py 
import csv, sys, zipfile

z         


        
4条回答
  •  旧时难觅i
    2020-12-09 02:30

    And if you just like to read a file into a string:

    with ZipFile('spam.zip') as myzip:
        with myzip.open('eggs.txt') as myfile:
           eggs = myfile.read().decode('UTF-8'))
    

提交回复
热议问题