Answer the question
In order to leave comments, you need to log in
Python string compression, why did the size change after concatenating with another string?
There is a dict structure, I distill it into a json string, I compress the json string, and then I collect a new string through string formatting. Why did the size of the final line increase by 3 times?
import json
import zlib
dict_data = {
'command': "send_files",
'files': ['images/elements/82.gif',
'images/elements/168.gif',
'images/elements/219.gif',
'images/elements/2yntZymm.png',
'images/elements/RGAlKgXS.png',
'images/elements/vedALO6A.png',
'images/elements/166.gif',
'images/elements/165.gif',
'images/elements/128.gif',
'images/elements/192.gif',
'images/elements/183.gif',
'images/elements/196.gif',
'images/elements/11.gif',
'images/elements/108.gif',
'images/elements/21.gif',
'images/elements/148.gif',
'images/elements/32.gif',
'images/elements/143.gif',
'images/elements/2vKwklHg.png',
'images/elements/106.gif'
]
}
json_data = json.dumps(dict_data)
print("Len json_data: %s" % len(json_data))
# Len json_data: 592
compress_data = zlib.compress(json_data.encode('utf-8'))
print("Len compress_data: %s" % len(compress_data))
# Len compress_data: 165
result_string = "{'compress_data':%s}" % compress_data
print("Len result_string: %s" % len(result_string))
# Len result_string: 495
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question