python output from a file like image, or npz file

I’ve tried to read a npz file and it turn out the output like below

b’PK\x04\x03\x14\x00\x00\x00\x07\x00\x05\x00!\x00M\xd05\xda\xa1\xb7\
x00\x00\x00\x07\x01\x00\x00\x06\x00\x14\x00PK.npy\x01\x00\x10\x00.

I know it is unreadable for human but I really want to know what is the meaning of every character like b, PK,\ and the number on it

what is the meaning of every character on those output? like the slash or number on it? is it just random or? please help me. Thank you

  • The PK\x03\x04\x14 at the beginning is an indicator of the file type. In this case it denotes the file is some type of compressed file.

    – 

Notation like the following means it is a Python bytes type:

b'......'

The P and K are just printable characters, i.e. the regular letters P and K.

The rest are hex representations of bytes, so \x04 just means a byte with the value 4.

You can display your binary data as 0’s and 1’s like this

xx = b'PK\x04\x03\x14\x00\x00\x00\x07'

for x in xx:
     print("{:08b}".format(x))

Output:

01010000
01001011
00000100
00000011
00010100
00000000
00000000
00000000
00000111

However, looking at the data is not equivalent to understanding its meaning. It only becomes meaningful if you know the specifications of the file format.

Leave a Comment