I had the following code working to convert a csv file to a dictionary.
with open(filename, encoding='utf-8') as file:
dictReader = csv.DictReader(file)
for row in dictReader:
#Do Work
These csv files arrive zipped and so I figured I'd attempt to modify the code to read the zipped csv files into a dictionary. Things get tricky since as I understand it, when opening a file inside a zip archive, the file is opened as bytes rather than text. I had it working where I was reading the entire file in, and converting it to text, but then I hit a large file and had a memory error. So I updated the code to read the file in one line at a time and now I suspect that I'll have to build the dictionary manually, but I figured it was worth asking here.
Thanks to pmsh.93, I now have it working.
with zipfile.ZipFile(filename) as zipFile:
for fname in zipFile.infolist():
with zipFile.open(fname) as file:
file = io.TextIOWrapper(file, encoding="utf-8")
for row in csv.DictReader(file):
#Do Work