【发布时间】:2018-08-29 02:18:50
【问题描述】:
在要处理的输入 XML 中,我有一个 URN UUID 作为文件标识符:
urn:vendor:processor:uuid:0269803d-50c4-46b0-9f50-60ef7fe3e22b
我需要检查此 UUID 是否有效,但 vendor:processor: 部分会使标准模块引发错误:
# same UUID in different flavors
x = "0269803d50c446b09f5060ef7fe3e22b"
y = "urn:uuid:0269803d-50c4-46b0-9f50-60ef7fe3e22b"
z = "urn:vendor:processor:uuid:0269803d-50c4-46b0-9f50-60ef7fe3e22b"
# testing different ways
uuid.UUID(x)
>>> UUID('0269803d-50c4-46b0-9f50-60ef7fe3e22b') # yipee
uuid.UUID(y)
>>> UUID('0269803d-50c4-46b0-9f50-60ef7fe3e22b') # yipee 2
uuid.UUID(z)
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\uuid.py", line 140, in __init__
raise ValueError('badly formed hexadecimal UUID string')
ValueError: badly formed hexadecimal UUID string
如何指定 vendor:processor: 是 UUID 命名空间的一部分(不确定这个术语是否正确)?
环境:Python 3.6.4 64 位 - Win10
【问题讨论】:
-
你能告诉我们哪个python版本吗?
-
当然,Python 3.6.4 64 位 - Win10。它在回溯路径中,但现在更容易了:)
-
字符串中的
z字符也是错字吗?例如x=...ez7...?