I need to print the comments of files inside a zip file :
import zipfile
def info_zip(archive_name):
with zipfile.ZipFile(archive_name) as challenge:
for info in challenge.infolist():
print(info.comment)
but the results i am get aren’t pretty:
b'G'
b' '
b'E'
b' '
b' '
b'*'
b'*'
b' '
b'E'
- How to get rid from those b at the start of every comment?
- Why are they like that, i know what they are mean buy isn’t the comment’s content is by the author of the zip file, why he would like to store them as binary ?
Python 3.x
The
bindicates that it is a bytes-object that is printed. To get from bytes to string you have to decode the bytes object (Encode is transform a string to a bytes object).In order to decode a bytes object you” have to know the used character encoding.
My guess is that the zip-file header is simply
ASCIIencoded. You should thus be able to get the wanted result by calling: