如何将字符串格式化为包含连字符的 UUID 格式
How can I format a string to UUID format that contains hyphens
我有一个看起来像这样的字符串。这是一个没有连字符的 UUID:
'0613ff4c000c0e08dda69667dc7d6c5b'
如何设置此字符串的格式,使其看起来像带有连字符的典型 UUID,如下所示:
'0613ff4c-000c-0e08-dda6-9667dc7d6c5b'
您可以使用标准库中的 the uuid module:
import uuid
original = '0613ff4c000c0e08dda69667dc7d6c5b'
str(uuid.UUID(original))
# '0613ff4c-000c-0e08-dda6-9667dc7d6c5b'
我有一个看起来像这样的字符串。这是一个没有连字符的 UUID:
'0613ff4c000c0e08dda69667dc7d6c5b'
如何设置此字符串的格式,使其看起来像带有连字符的典型 UUID,如下所示:
'0613ff4c-000c-0e08-dda6-9667dc7d6c5b'
您可以使用标准库中的 the uuid module:
import uuid
original = '0613ff4c000c0e08dda69667dc7d6c5b'
str(uuid.UUID(original))
# '0613ff4c-000c-0e08-dda6-9667dc7d6c5b'