python - 不要在文本的开头或结尾去除空格 - 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?')
输出应该是“什么是纱架?” 不是“什么是纱架”。如何在文本的开头或结尾保留空格?
解决方案
您的输入最后缺少空间:
>>> hex(1612388154947973357665)
'0x576861742069732061'
>>> # manually add \x for every pair of digits:
>>> '\x57\x68\x61\x74\x20\x69\x73\x20\x61'
'What is a'
推荐阅读
- regex - 如何使用 .htaccess 重写 mp3 文件名
- c++ - 在不构造字符串对象的情况下使用 std::string 的 std::hash 特化
- selenium - 将 WebDriver 从 GUI 更改为 Headless
- android - 如何更新已弃用的 com.google.api.client.extensions.android.http.AndroidHttp
- android - 您可以在 Android Studio 中的 Android Emulator 设备和 USB 连接的真实设备之间发送通知,以便与数据库进行演示吗?
- python - os.Pathlike 对象的 pyinstaller 错误
- php - 如何将php搜索结果输出到html表?
- google-play-console - Play 控制台:在哪里可以找到运行我的应用程序的设备列表?
- android - 找出 GPGS android API 中的 profileSettings.profileVisible 是否存在?
- php - Cookie 在调用时返回先前的值