Create GUID with Python

Asked 2 years ago, Updated 2 years ago, 31 views

Is there a way to create a that works on all platforms?

I heard that you use Active Python on Windows I need code that works regardless of Linux Unix or something.

python guid uuid

2022-09-22 22:17

1 Answers

The uuid module has been accepted as standard since python 2.5 and above.

Based on python3, approximately

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.

Create a UUID based on host ID, sequence number, and current time. If node is not given, obtain the address of the hardware with getnode(). If clock_seq is given, write clock_seq as sequence number, otherwise create a random 14-bit

Generate a UUID based on the MD5 hash of a namespace identifier (which is a UUID) and a name (which is a string).

namespace the identifier and 5 md name uuid based on generate.

Generate a random UUID.

Create a random UUID

Generate a UUID based on the SHA-1 hash of a namespace identifier (which is a UUID) and a name (which is a string).

Generate a UUID based on the SHA-1 hash of the namespace identifier and name.

>>> import uuid
>>> uuid.uuid4()
UUID('5361a11b-615c-42bf-9bdb-e2c3790ada14')


2022-09-22 22:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.