Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the number of characters in a python uuid (type 4)?

Tags:

python

uuid

I'm building a database to hold a uuid generated by the python uuid4 method - however, the documentation doesn't mention how many chars the uuid is!

I'm not overly familiar with uuids, so i don't know if all languages generate the same length for a uuid.

like image 602
bharal Avatar asked Dec 09 '12 05:12

bharal


1 Answers

There is a standard for UUIDs, so they're the same in all languages. However, there is a string representation and a binary representation. The normal string representation (str(myuuid)) looks like 42c151a8-b22b-4cd5-b103-21bdb882e489 and is 36 characters. The binary representation, myuuid.bytes (or bytes_le, but stay consistent with it when reconstructing the UUID objects), is 16 bytes. You can also get the string representation with no hyphens (32 characters) with myuuid.hex.

You should be aware that some databases have a specific UUID type for storing UUIDs. What kind of database are you using?

like image 96
Random832 Avatar answered Oct 23 '22 07:10

Random832