比如说定义了一个类FooBar,搞出了一个对象foobar
想要 not foobar == True。
想要 not foobar == True。
1
phuslu Aug 27, 2013 __nonzero__ 方法
http://www.rafekettler.com/magicmethods.html |
3
thedevil5032 Aug 28, 2013 via iPad
If not foobar 就可以了,不用再 ==,参考的是 PEP8。
|
4
tioover OP @thedevil5032 我只是表示一下,就是为了写你这种语句。
|
5
tioover OP 调试了半天没发现问题,原来因为Py3k 已经没有__nonzero__ 了 orz
__bool__ |