Python generates UUID

Source: Internet
Author: User
Tags md5 hash

The globally unique identifier (guid,globally unique Identifier) is also known as the UUID (universally unique Identifier).

There are UUID libraries in Python that can generate different types of UUID:

Import uuiduuid.uuid1 ()

The result is:

UUID ('f6922dc0-0c45-11e5-a62e-b8763facf5a5')

There are also UUID2,UUID3,UUID4,UUID5, but there is no uuid2 in Python.

>>>ImportUUID>>>#Make a UUID based on the host ID and current time>>>uuid.uuid1 () uuid ('a8098c1a-f86e-11da-bd1a-00112444be1e')>>>#Make a UUID using a MD5 hash of a namespace uuid and a name>>> uuid.uuid3 (UUID. Namespace_dns,'python.org') UUID ('6fa459ea-ee8a-3ca4-894e-db77e160355e')>>>#Make a random UUID>>>Uuid.uuid4 () uuid ('16fd2706-8baf-433b-82eb-8c7fada847da')>>>#Make a UUID using a SHA-1 hash of a namespace uuid and a name>>> UUID.UUID5 (UUID. Namespace_dns,'python.org') UUID ('886313e1-3b8a-5372-9b90-0c9aee199e5d')>>>#Make a UUID from a string of hex digits (braces and hyphens ignored)>>> x = uuid. UUID ('{00010203-0405-0607-0809-0a0b0c0d0e0f}')>>>#convert a UUID to a string of hex digits in standard form>>>str (x)'00010203-0405-0607-0809-0a0b0c0d0e0f'>>>#get the raw bytes of the UUID>>>x.bytes'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'>>>#Make a UUID from a 16-byte string>>> UUID. UUID (bytes=x.bytes) UUID ('00010203-0405-0607-0809-0a0b0c0d0e0f')

More Information reference: https://docs.python.org/2/library/uuid.html

Python generates UUID

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.