I tried to generate uuid with the following code.
import uuid print (uuid.uuid4 ())
No matter how many times you try,
Since uuids with capital letters were not generated like this, is it okay to assume that this is the default setting?
Answer # 1
To RFC4122 where UUID specification is defined
The hexadecimal values "a" through "f" are output as lower case characters and are case insensitive on input.
, the Python uuid library just follows that specification.
UUID is an integer value of 128 bits. It is handled as one large integer value * on the memory. When generating a UUID, this one large integer value is generated according to a different rule for each version of the UUID. In other words, it is just an integer value inside the program.
※ In fact, in many languages and environments including C, there is no fixed-length integer type that can directly contain 128-bit integer values, so it is divided into multiple integer values internally, or a 16-octet string It seems that it is managed as.
Also, this single large integer value does not have a single meaning in the whole integer, but there is a delimiter called a field in a certain bit range. For example, a specific part of a field has the role of indicating the version.
Now, it is good if it is completed inside the program, but when exchanging data, especially when exchanging as text data, it is too large to express as an integer in decimal. Also, the meaning of each field is not well understood in decimal numbers. In the first place, UUID was created to be usable as URN, so it must be able to be expressed in text. That's the format in which the hexadecimal numbers we normally see as UUIDs are separated by
-. In addition, by separating the specific positions with
-, it is easy to grasp the field from the human eye and it is easy to distinguish. (The meaning of each place depends on the version, so it's hard to say)
This hexadecimal number separated by
-is also UUID, but this is expressed as URN and is used when exchanging as text data. It is still treated as an integer value of 128 bits. In other words, a mechanism for converting them to each other must be established. Hexadecimal numbers are used as one of the rules, but lowercase letters are used to output text from internal representation integer values, and uppercase and lowercase letters are used to convert input text to internal representation integer values. It is supposed to be ignored.
That is, when generating a UUID and getting its text, the program works as follows:
A 128bits integer value is generated according to the rules defined for each version.
Convert to integer value hexadecimal. At this time, use lowercase letters (
-at a specific position.
Depending on the implementation, steps 2 and 3 may be mixed (connect with
-afterwards). However, (unless it's a very strange implementation), basically you create an integer value first and then convert it to a hexadecimal string, not a string directly.
There is an IP address as an example where the internal representation and text representation are different. IPv4 is just a 4-octet sequence internally and exists as a 4-octet sequence inside the packet. However, in settings and expressions, four decimal numbers (0 to 255) are separated by
.. When a program that handles IP addresses handles IPv4 text notation, the reason for using decimal numbers instead of hexadecimal numbers, and the reason to use
.as a delimiter for each octet is the same as in IPv4 for RFC. Since it is stipulated that it is written in, it is only implemented that way. The same is true for UUIDs, just say that each library only follows the RFC.
- python - the generated object will be cut off in 10 seconds
- python - i want to convert the characters obtained from the txt file to numbers
- python - garbled characters of ˚c in the image
- python - the table element generated by the django template variable is output at the bottom of the page
- get the number of characters from the python text box
- python 3x - when accessing the internally generated tfdataset during execution from the console, the program ends
- cgi using python does not recognize the mysqldb library
- python - pydrive cannot recognize folders in shared drive
- python 3x - supports garbled characters for web scraping
- python - about garbled characters in webbroeser
- python - sumy by specifying the maximum number of characters with sumy
- python - when you want to judge by the number of characters from the back with a regular expression
- php - i want to implement 6 or more single-byte alphanumeric characters on the user registration screen
- python - when i try to erase non-ascii characters in the text with resub (r "[^ x00-x7f]", r "", text), the
- python - i downloaded openpyxl, but it doesn't recognize the xlsx file and i have stopped studying
- python - how to store the characters in the list in the dictionary
- python - i want to arrange the characters so that they are not covered (like a permutation) how can i do this?
- python - i want to fix the garbled characters that occur when opening a csv file in excel on vscode
- python - when i use write (), the characters are not displayed
- python - how to search for duplicate characters in the character string