python으로 GUID 만들기
조회수 4316회
발생하는 문제 및 실행환경
모든 플랫폼에서 동작하는 를 짜는 방법이 있을까요?
윈도우에서는 ActivePython을 쓰는 걸로 알고있는데 저는 리눅스 유닉스 그런거 상관없이 다 동작하는 코드가 필요합니다.
1 답변
-
python 2.5이상부터 uuid 모듈을 표준으로 인정했습니다.
- Python 2: http://docs.python.org/2/library/uuid.html
- Python 3: https://docs.python.org/3/library/uuid.html
python3을 기준으로 해석해보면 대략
1. uuid.uuid1(node=None, clock_seq=None)
Generate a UUID from a host ID, sequence number, and the current time. If node is not given, getnode() is used to obtain the hardware address. If clock_seq is given, it is used as the sequence number; otherwise a random 14-bit sequence number is chosen.
host ID, sequence number, 현재 시간을 기준으로 UUID를 생성합니다.
node
가 주어지지 않을 경우에는getnode()
로 하드웨어의 주소를 얻습니다.clock_seq
가 주어진 경우clock_seq
를 sequence number로 쓰고 그렇지 않은 경우는 랜덤 14-bit을 만들어냅니다2. uuid.uuid3(namespace, name)
Generate a UUID based on the MD5 hash of a namespace identifier (which is a UUID) and a name (which is a string).
namespace
식별자의 MD5와name
을 기준으로 UUID를 생성합니다.3. uuid.uuid4()
Generate a random UUID.
랜덤 UUID를 생성합니다
4. uuid.uuid5(namespace, name)
Generate a UUID based on the SHA-1 hash of a namespace identifier (which is a UUID) and a name (which is a string).
namespace
식별자의 SHA-1 해시와name
을 기준으로 UUID를 생성합니다.사용 예 :
>>> import uuid >>> uuid.uuid4() UUID('5361a11b-615c-42bf-9bdb-e2c3790ada14')
댓글 입력