如何将字符串格式化为包含连字符的 UUID 格式 [英] How can I format a string to UUID format that contains hyphens
本文介绍了如何将字符串格式化为包含连字符的 UUID 格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像这样的字符串.这是一个没有连字符的 UUID:
I have a string that looks like this. It's a UUID without the hyphens:
'0613ff4c000c0e08dda69667dc7d6c5b'
如何将此字符串的格式设置为带有如下连字符的典型 UUID:
How can I format this string to look like a typical UUID with hyphens like the following:
'0613ff4c-000c-0e08-dda6-9667dc7d6c5b'
推荐答案
您可以使用 来自标准库的 uuid 模块:
import uuid
original = '0613ff4c000c0e08dda69667dc7d6c5b'
str(uuid.UUID(original))
# '0613ff4c-000c-0e08-dda6-9667dc7d6c5b'
这篇关于如何将字符串格式化为包含连字符的 UUID 格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文