擅长:python、mysql、java
<p>您发布的代码是正确的,并且可以同时使用Python2.7和3.6(对于3.6,必须在print语句周围加上括号)。但是,代码按原样缩进了3个空格,应该固定为4个空格。</p>
<p>如何再现你的错误</p>
<pre><code>s = []
str = 'overload str with string'
# The str below is a string and not function, hence the error
s.append(' '.join(str(x) for x in ['a', 'b', 'c']))
print(s)
Traceback (most recent call last):
File "python", line 4, in <module>
File "python", line 4, in <genexpr>
TypeError: 'str' object is not callable
</code></pre>
<p>必须在某个地方将str builtin</strong>运算符重新定义为str value</strong>,如上面的示例所示。</p>
<p>这里是同一问题的一个较浅的例子</p>
<pre><code>a = 'foo'
a()
Traceback (most recent call last):
File "python", line 2, in <module>
TypeError: 'str' object is not callable
</code></pre>