I tried
with zipfile.ZipFile(\"5.csv.zip\", \"r\") as zfile:
for name in zfile.namelist():
with zfile.open(name, \'rU\') as readFile:
To convert a byte stream into Unicode stream, you could use io.TextIOWrapper():
encoding = 'utf-8'
with zipfile.ZipFile("5.csv.zip") as zfile:
for name in zfile.namelist():
with zfile.open(name) as readfile:
for line in io.TextIOWrapper(readfile, encoding):
print(repr(line))
Note: TextIOWrapper()
uses universal newline mode by default. rU
mode in zfile.open()
is deprecated since version 3.4.
It avoids issues with multibyte encodings described in @Peter DeGlopper's answer.