gpt4 book ai didi

.net - IronPython - 将 int 转换为字节数组

转载 作者:行者123 更新时间:2023-11-28 22:07:59 25 4
gpt4 key购买 nike

在 Python 中获取字符串的长度,然后将其转换为字节数组的正确方法是什么?将其打印到控制台进行测试的正确方法是什么?

最佳答案

使用struct .

import struct

print struct.pack('L', len("some string")) # int to a (long) byte array

关于.net - IronPython - 将 int 转换为字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/796197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com