728x90
반응형
UUID란?
uuid는 네트워크 상에서 중복되지 않는 고유한 식별자인 UUID(Universally Unique IDentifier)를 생성할 때 사용하는 모듈이다.
uuid.uuid1(node=None, clock_seq=None)
호스트 ID, sequence 번호 및 현재 시각으로 UUID를 생성한다. node가 주어지지 않으면, getnode()를 사용하여 하드웨어 주소를 얻는다. clock_seq가 주어지면 시퀀스 번호로 사용한다. 그렇지 않을 경우, 무작위 14bit 시퀀스 번호를 사용한다.
uuid.uuid3(namespace, name)
이름 공간 식별자(UUID) 및 이름(문자열)의 MD5 해시를 기반으로 UUID를 생성한다.
uuid.uuid4()
무작위 UUID를 생성한다.
uuid.uuid5(namespace, name)
이름 공간 식별자(UUID) 및 이름(문자열)의 SHA-1 해시를 기반으로 UUID를 생성한다.
Example
import uuid
# make a UUID based on the host ID and current time
uuid.uuid1()
UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')
# make a UUID using an 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 16 bytes of the UUID
x.bytes
b'\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')
Reference
- https://docs.python.org/ko/3/library/uuid.html
- https://wikidocs.net/131351
- https://dpdpwl.tistory.com/77
반응형
'Programming Language > [Python]' 카테고리의 다른 글
[Python] selenium.common.exceptions.ElementClickInterceptedException (1) | 2024.02.28 |
---|---|
[Python] ValueError: If using all scalar values, you must pass an index (0) | 2023.11.10 |
[Python] pandas dataframe 행/열 count (0) | 2023.07.12 |
[Python] pymysql connection option (0) | 2023.06.21 |
[Python] Jinja template (0) | 2023.04.30 |