Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Str对象在Spyder中不可调用_Python - Fatal编程技术网

Python Str对象在Spyder中不可调用

Python Str对象在Spyder中不可调用,python,Python,我一直在尝试在Spyder(python 2.7)中使用str()函数将整数转换为字符串。每次我得到TypeError时:“str”对象不可调用 例如,我编写了这个简单的代码来测试它,我得到了相同的错误: x = 5 print str(x) 有人能帮我一下吗?您已经在代码中的某个地方覆盖了内置的str >>> str = 'foo' # overwriting the builtin `str` >>> x = 5 >>> print

我一直在尝试在Spyder(python 2.7)中使用str()函数将整数转换为字符串。每次我得到
TypeError时:“str”对象不可调用

例如,我编写了这个简单的代码来测试它,我得到了相同的错误:

x = 5
print str(x)

有人能帮我一下吗?

您已经在代码中的某个地方覆盖了内置的
str

>>> str = 'foo'   # overwriting the builtin `str`
>>> x = 5
>>> print str(x)  # equivalent to 'foo'(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
str='foo'#覆盖内置的'str'` >>>x=5 >>>打印str(x)#相当于“foo”(x) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 TypeError:“str”对象不可调用
您可能创建了另一个名为
str
的变量。如果你在一个全新的解释器会话中运行该代码,它就不会给出那个错误。我检查了我的代码,但在任何地方都没有找到str!还有其他方法可以将int转换为String吗?@Nasser:再次检查代码。您是否从任何导入*导入任何模块,如
?如果是,也检查这些模块。另外,在打印str(x)
do
print repr(str)
之前。这应该能帮你解决问题。