- Code: Select all
zfile = zipfile.ZipFile('ziparchive.zip', 'r')
all_indexes = 
file_contents = zfile.read('90052.txt')
match = re.findall(b'\d+', file_contents)
# break if there are no numbers so the length of the 'match' list is 0
if len(match) == 0:
index_file = match.decode("utf-8")
next_file = index_file + ".txt"
file_contents = zfile.read(next_file)
print('.'.join([zfile.getinfo(i).comment.decode("utf-8") for i in all_indexes]))
Could you have a look at it and suggest any improvements? I mean it works okay but I'm far from expert and not sure if I'm not doing something in a clumsy and/or not recommended way.
Also, it it really necessary to decode it from bytes to strings in 2 places? Would not it possible to do it once?