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

标签 .net python ironpython arrays

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

最佳答案

使用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/

相关文章:

python - python setup.py install 可以使用轮子吗?

python - 在表中插入总行数,不使用 Pandas,仅使用循环

c# - IronPython 中的 DateTime.Now.AddSeconds 等价物

.net - 程序集引用的 "Specific Version"属性在 Visual Studio 中究竟是如何工作的?

c# - 为什么没有接受 Doubles 作为参数的 Interlocked.Add 重载?

C# - 在声明中设置初始值的缺点

python - 如何防止 Sphinx 将 "object"列为基类?

python - 正在寻找可能更好的方法来使用 Glom 获取嵌套数据?

python - IronPython - sys.exit() 上的正确资源释放

c# - 从程序集中获取所有 DLLImports?