Python 之 UUID

  • UUID是根据MAC以及当前时间等创建的不重复的随机字符串
import uuid

# Generate a UUID from a host ID, sequence number, and the current time
>>> uuid.uuid1()

# Generate a UUID from the MD5 hash of a namespace UUID and a name
>>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')

# Generate a random UUID
>>> uuid.uuid4()

# Generate a UUID from the SHA-1 hash of a namespace UUID and a name
>>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')

# make a UUID from a string of hex digits(braces and hypens ignored)
>>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}')

# convert a UUID to a string of hex digits in standard form
>>> str(x)
原文地址:https://www.cnblogs.com/linkworld/p/8733372.html