zak*_*ces 2 python uuid exception
会抛出异常吗?UUID()是否曾默默失败?是否存在'myStatus'来自的任何情况
myStatus = True
myUUID = uuid.UUID( someWeirdValue )
if myUUID == None:
myStatus = False
Run Code Online (Sandbox Code Playgroud)
会等于假吗?
该UUID()构造或者提出了一个TypeError或一个ValueError,具体内容取决于传入.
不经过任何的hex,bytes,bytes_le,fields,或int选择提出了TypeError,通过在该声明是无效的价值会引起ValueError:
>>> uuid.UUID()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/uuid.py", line 129, in __init__
raise TypeError('need one of hex, bytes, bytes_le, fields, or int')
TypeError: need one of hex, bytes, bytes_le, fields, or int
>>> uuid.UUID('abcd')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/uuid.py", line 134, in __init__
raise ValueError('badly formed hexadecimal UUID string')
ValueError: badly formed hexadecimal UUID string
>>> uuid.UUID(bytes='abcd')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/uuid.py", line 144, in __init__
raise ValueError('bytes is not a 16-char string')
ValueError: bytes is not a 16-char string
Run Code Online (Sandbox Code Playgroud)
等等
它不会无声地失败.它肯定永远不会回来None.要么myUUID设置为UUID实例,要么引发异常.
| 归档时间: |
|
| 查看次数: |
2286 次 |
| 最近记录: |