Uuid.uuid4() output type?

This is the place for queries that don't fit in any of the other categories.

Uuid.uuid4() output type?

Postby ehmoja » Mon Dec 30, 2013 3:14 pm


i basically want to know what data type is the output of the function, uuid.uuid4() and how can i change strings to it.

I am using the function in the following code and what is really confusing me, is that the function len(enc_key.bytes) returns 16 for the else branch but when I enter the exact same thing into the tkSimpleDialog.askstring() of the if branch, it says the str object has no attribute 'bytes'. I was under the impression that uuid.uuid4() returns a string either way.

Also, i would appreciate it if you could say how i could convert the user input from tkSimpleDialog.askstring()
into a data structure that can be plugged into a DES encryption, because my main problem is that right now pyDES won't accept the user input of tkSimpleDialog.askstring() as a valid encryption key on grounds of it not being a 16 or 24 byte key.

Here is the code for reference:

Code: Select all
def create_key():
    global enc_key
    _here = os.path.dirname(os.path.abspath(__file__))
    filename = os.path.join(_here, 'checkfile.txt')
    if os.path.isfile(filename):
        enc_key = tkSimpleDialog.askstring( "Enigma Password Manager", "Please enter your encryption key (with dashes).")
        key = uuid.uuid4()
        tkMessageBox.showinfo( "Enigma Password Manager", "Your unique encryption key has been copied to your clipboard. Please note it down:" + str(key))
        enc_key = key
        open(filename, 'w')
        open(passfile.txt, 'w')
Last edited by Mekire on Mon Dec 30, 2013 4:06 pm, edited 1 time in total.
Reason: First post lock.
Posts: 2
Joined: Mon Dec 30, 2013 3:08 pm

Re: Uuid.uuid4() output type?

Postby ehmoja » Mon Dec 30, 2013 4:52 pm


I found something in answer to my own question on a a manual saying that to convert strings into uuid format, i need to use the uuid.UUID() function.

However, their explaination for the function's use was vague so right now, I would be very grateful if someone could just explain to me how to use uuid.UUID() on a string.
Posts: 2
Joined: Mon Dec 30, 2013 3:08 pm

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 9 guests