不要去除文本开头或结尾的空格 - Python

Do not strip White spaces at the beginning or end of a text - Python

我在 Python 中有这段代码,可以将小数转换为相应的 ASCII 字符。

import codecs
def convert_decimal_to_string(decrypted):
    decrypted = hex(decrypted)
    decrypted = decrypted.replace('0x', '')        
    return codecs.decode(codecs.decode(decrypted,'hex'),'ascii')

decrypted = 1612388154947973357665
decrypted = convert_decimal_to_string(decrypted)
print(decrypted + 'Creel?')

输出应该是 "What is a Creel?" 而不是 "What is aCreel" 。如何保留文本开头或结尾的空格?

您输入的末尾缺少 space:

>>> hex(1612388154947973357665)
'0x576861742069732061'
>>> # manually add \x for every pair of digits:
>>> '\x57\x68\x61\x74\x20\x69\x73\x20\x61'
'What is a'