Python UUID badly formed hexadecimal string
Question
Trying to generate a UUID based on an 6.6 XY coordinate pair and the date. However I am giving the function a 'badly formed hexadecimal UUID string'. Python noob plz help.
def LeID(Xv,Yv,Dv):
import uuid
import string
import arcpy
X_val = "%.6f" % Xv
Y_val = "%.6f" % Yv
date = Dv
xarr = string.split(X_val, '.')
yarr = string.split(Y_val, '.')
date = string.split(date , '/')
val = str(xarr[0] + xarr[1] + yarr[0] + yarr[1] + date[0] + date[1] + date[2] )
return '{' + str(uuid.UUID(val).time_low()) + '}'
Solution
It won't work the way you think.
There are several types of UUID: based on time (UUID1), randomly (UUID4) or based on another UUID plus data, put together via MD5 (UUID3) or SHA1 (UUID5).
So you would take one previously defined UUID, maybe UUID('f82aa75f-56a8-442b-89d2-eb7aaae6f9c3')
, as a namespace and derive all from this.
def LeID(Xv,Yv,Dv):
import uuid
import string
import arcpy
MyNS = uuid.UUID('f82aa75f-56a8-442b-89d2-eb7aaae6f9c3')
X_val = "%.6f" % Xv
Y_val = "%.6f" % Yv
date = Dv
xarr = string.split(X_val, '.')
yarr = string.split(Y_val, '.')
date = string.split(date , '/')
val = str(xarr[0] + xarr[1] + yarr[0] + yarr[1] + date[0] + date[1] + date[2] )
print MyNS, repr(val) # for debugging
return '{' + str(uuid.uuid5(MyNS, val)) + '}'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow