Ironpython数组[byte]到字节字符串

时间:2014-07-30 21:16:48

标签: arrays string ironpython

在IronPython 2.7中,我正在运行一些.Net dll的调用:

from System.Guid import NewGuid, ToByteArray
from System import Array, Byte
import clr
clr.AddReferenceToFile( ThePathToDLLFile )
from MyDLL import *
...
g = NewGuid()
buffer = ToByteArray(g)
ret = myDllMethodToFillBuffer( buffer )

像myDllMethod'返回Array [byte]类型的缓冲区:

>>> type(buffer)
<type 'Array[Byte]'>

我很想找到将Array [byte]转换为Python&#39; string byte&#39;,IE&#39; \ x01 \ x02 \ x03 ......&#39;

经过一段谷歌搜索后,我找到了进行相反转换的方法(字符串字节到字节[数组])

byteArray = Array[Byte](ord(c) for c in byteList)

我应该如何将可变长度字节[数组]转换为字符串字节?

1 个答案:

答案 0 :(得分:1)

使用bytes功能:

>>> bytes(Guid.NewGuid().ToByteArray())
b'\x14\x15\xd4\x05\xe4\xc2\xa8N\x9a\x99\t\x82\xe41r\xb3'