为什么我不能将 itertools.chain 对象转换为 Jython 中的列表

Why can't I cast itertools.chain object to list in Jython

在Python中:

list(itertools.chain.from_iterable(['aaa','bbb']))

给出:

['a','a','a','b','b','b']

符合预期。 在 Jython 2.7.0 中,相同的代码给出 TypeError: 'str' object is not callable.

请注意,这似乎是尝试转换为给出错误的列表,因为

for c in itertools.chain.from_iterable(['aaa','bbb']):
     lst.append(c)

构建所需的列表。

我怀疑 Jython 没有问题,您只是声明了一个名为 list 的变量并为其分配了一个字符串值。

运行 del list 去掉隐藏内置函数的名称,然后重试,它应该也适用于 Jython。