为什么没有"不是"在列表理解中使用ConfigParser.sections()?

时间:2015-11-28 05:17:49

标签: python python-3.x list-comprehension configparser

我有以下代码:

#!/usr/bin/python3

import configparser

config = configparser.ConfigParser()

config.read('bindslash.ini')

print([name for name in config.sections() if name is not 'bindslash'])

bindslash.ini看起来像这样:

[bindslash]

[somethingelse]

运行此程序会生成['bindslash', 'somethingelse']。但是,如果我将列表解析中的is not改为!=,则程序会正确生成['somethingelse']。据我了解,这些应该完全相同。为什么没有is not工作?

我在Python 3.5.0上,在OS X上从Homebrew安装。

0 个答案:

没有答案