2

Within IronPython 2.7, I am running a few calls to a .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 )

Some methods like 'myDllMethod' return a buffer of type Array[byte]:

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

I am strugling to find the right way to convert the Array[byte] to Python 'string byte', IE '\x01\x02\x03 ...'

After a bit of googling I found the way to do the opposite conversion (string byte to byte[array])

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

How should I convert a variable length byte[array] to string byte?

1 Answer 1

1

Use the bytes function:

>>> bytes(Guid.NewGuid().ToByteArray())
b'\x14\x15\xd4\x05\xe4\xc2\xa8N\x9a\x99\t\x82\xe41r\xb3'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.