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

前端 未结 4 786
我寻月下人不归
我寻月下人不归 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条回答
  •  时光取名叫无心
    2020-12-09 02:14

    You can wrap it in a io.TextIOWrapper.

    items_file  = io.TextIOWrapper(items_file, encoding='your-encoding', newline='')
    

    Should work.

提交回复
热议问题