Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a Python UUID into a string?

I need to be able to assign a UUID to a user and document this in a .txt file. This is all I have:

import uuid  a = input("What's your name?") print(uuid.uuid1()) f.open(#file.txt) 

I tried:

f.write(uuid.uuid1()) 

but nothing comes up, may be a logical error but I don't know.

like image 313
Alphin Philip Avatar asked May 05 '16 11:05

Alphin Philip


People also ask

How do you use UUID in Python?

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() .

Is Python UUID thread safe?

The thread-unsafe part of Python 2.5's uuid. uuid1() is when it compares the current current timestamp to the previous timestamp. Without a lock, two processes can end up comparing against the same globally saved timestamp.

How does Python compare UUID?

As Giacomo Alzetta says, UUIDs can be compared as any other object, using == . The UUID constructor normalises the strings, so that it does not matter if the UUID is in a non-standard form. You can convert UUIDs to strings using str(x) , or strings into UUID objects using uuid.

How do you make a unique UUID in Python?

uuid1() is defined in UUID library and helps to generate the random id using MAC address and time component. bytes : Returns id in form of 16 byte string. int : Returns id in form of 128-bit integer. hex : Returns random id as 32 character hexadecimal string.


1 Answers

you can try this !

 a = uuid.uuid1()  str(a)  --> '448096f0-12b4-11e6-88f1-180373e5e84a' 
like image 160
sumit Avatar answered Oct 10 '22 22:10

sumit