How do you concatenate the uuid.uuid4() value with a literal when creating a file? The below isn't correct but should illustrate what I'm attempting to do...
fo = open(uuid.uuid4() + ".txt", "wb")
UUID, Universal Unique Identifier, is a python library which helps in generating random objects of 128 bits as ids. It provides the uniqueness as it generates ids on the basis of time, Computer hardware (MAC etc.).
uuid4() creates a random UUID. New in version 3.7. The UUID was generated by the platform in a multiprocessing-safe way. The UUID was not generated in a multiprocessing-safe way.
The uuid module provides immutable UUID objects (the UUID class) and the functions uuid1() , uuid3() , uuid4() , uuid5() for generating version 1, 3, 4, and 5 UUIDs as specified in RFC 4122. If all you want is a unique ID, you should probably call uuid1() or uuid4() .
UUID 1 to Generate a unique ID using MAC AddressThe uuid. uuid1() function is used to generate a UUID from the host ID, sequence number, and the current time. It uses the MAC address of a host as a source of uniqueness. The node and clock_seq are optional arguments.
You need to convert the uuid
to a str
:
>>> import uuid
>>> str(uuid.uuid4()) + ".txt"
'13eb9327-f40e-4ef1-8020-1c36af1b4b70.txt'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With