Analysis of uuid Module Example in python

  • 2021-09-05 00:22:00
  • OfStack

Many people don't understand, Learning these unpopular functions is basically unnecessary. Or what is of great use, in fact, there are many uses. For example, the uuid module introduced to you today can generate a real random number, and can also generate only 1ID for the database, which can be used in many places. Interested partners can follow this site and learn about it seriously.

Module installation:


pip install uuid

Module import:


import uuid

Usage scenario:

1. Be able to generate timestamps

2. Random numbers can be generated

Usage:


import uuid
uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')

Instance extension


#-*- encoding: gb2312 -*-
import uuid
print uuid.uuid1()
print uuid.uuid3(uuid.NAMESPACE_DNS, 'testme')
print uuid.uuid4()
print uuid.uuid5(uuid.NAMESPACE_DNS, 'testme')

Related articles: