如何在 UUID 字符串中插入连字符?

fij*_*iji 3 python uuid

我想创建一个函数,-在 UUID 字符串的位置 8、12、16、20 上添加一个。

例子:

Original: 76684739331d422cb93e5057c112b637
New: 76684739-331d-422c-b93e-5057c112b637
Run Code Online (Sandbox Code Playgroud)

我不知道如何将它放置在看起来不像意大利面条代码的字符串中的多个位置。

Mar*_*nen 12

看起来您正在使用 UUID。Python有一个标准库:

import uuid
s = '76684739331d422cb93e5057c112b637'
u = uuid.UUID(hex=s)
print(u)
Run Code Online (Sandbox Code Playgroud)
76684739-331d-422c-b93e-5057c112b637
Run Code Online (Sandbox Code Playgroud)