Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert hyphens into a UUID string? [duplicate]

Tags:

python

uuid

I want to create a function that adds a - on position 8, 12, 16, 20 of a UUID string.

Example:

Original: 76684739331d422cb93e5057c112b637
New: 76684739-331d-422c-b93e-5057c112b637

I have no clue on how to position it on multiple positions in a string that wouldn't look like spaghetti code.

like image 837
fiji Avatar asked Oct 16 '25 16:10

fiji


1 Answers

It looks like you are working with UUIDs. There's a library for that that comes standard with Python:

import uuid
s = '76684739331d422cb93e5057c112b637'
u = uuid.UUID(hex=s)
print(u)
76684739-331d-422c-b93e-5057c112b637
like image 67
Mark Tolonen Avatar answered Oct 18 '25 18:10

Mark Tolonen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!