开发者

python: convert UUID to a string which is a C unsigned char[16] initializer

开发者 https://www.devze.com 2022-12-17 16:21 出处:网络
(in case you\'re curious about motivation: this will be used in a scons build to generate a C file containing a GUID)

(in case you're curious about motivation: this will be used in a scons build to generate a C file containing a GUID)

I found the question about generating a GUID in python. But I don't really know much about programming python. Could someone help me convert this to a string of the form

"{0x**, 0x**, 0x**, 0x**, 0x**, 0x**, 0x**, 0x**, 0x**, 0x**, 0x**, 0x**, 0x**, 0x**, 0x**, 0x**}"

where the **'s are filled in with the GUID bytes in 2开发者_JS百科-digit hex form?

def getInitializer(someUUID):
    hexByteList = [??? for b in someUUID.bytes]
    return '{'+(', '.join(hexByteList))+'}'

I'm not sure what to use for the "???" above.


hex(ord(b))

...

0

精彩评论

暂无评论...
验证码 换一张
取 消