最近因为工作需要,频繁使用python来写脚本,有时候你会感叹这么语言的神奇和强大的功能,有时候又会死于毙命。今天就是因为一些小问题搞了一天,脑壳疼。
首先就是None,这是个啥玩意儿,啥也不是。因为在做判断得时候遇到了None,这个玩意儿怎么判都不行,怎么判都不对,搞不明白!
a=None
b=''
if a==b:
print '相等'
else:
print '不相等'
print(type(a))
print(a)
print(type(b))
print(b)
if b is None:
print 'b is None'
if b is not None:
print 'b is not None'
if b:
print 'b is None'
if not b:
print 'b is not None'
print 'hello'
输出结果:
不相等
<type 'NoneType'>
None
<type 'str'>
b is not None
b is not None
hello
怎么判都不行,于是乎一顿搜索:添加链接描述
还有就是eval()函数,遇到None会抛异常,处理了很多次,最后try catch 去catch中处理了。