use*_*934 2 python macos ipython typeerror amazon-web-services
我有两个iPython笔记本电脑安装.一个在AWS Micro Instance上,第二个在我的Macbook上使用Anaconda(OS X Yosemite).我遇到两种处理以下代码的方式有所不同:
my_list = [1, 2, 3, 0, 5, 10, 11, 1, 5]
your_list = [1, 2, 3, 0, 12, 13]
my_set = set(my_list)
your_set = set(your_list)
print my_set
print len(my_set)
print len(my_list)
Run Code Online (Sandbox Code Playgroud)
在iPython-AWS上,我的输出是:
set([0, 1, 2, 3, 5, 10, 11])
7
9
Run Code Online (Sandbox Code Playgroud)
在iPython-Macbook上,我的输出是:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-29-cd060f1b0bde> in <module>()
1 my_list = [1, 2, 3, 0, 5, 10, 11, 1, 5]
2 your_list = [1, 2, 3, 0, 12, 13]
----> 3 my_set = set(my_list)
4 your_set = set(your_list)
5 print my_set
TypeError: 'set' object is not callable
Run Code Online (Sandbox Code Playgroud)
此外,这些是安装细节(如果相关):1.AWS Micro Instance上的iPython:http://i.stack.imgur.com/qYrq8.png
我似乎无法找到造成这种差异的原因,尽管我在Stackoverflow上遇到过很多关于"TypeError:'set'对象不可调用"的问题.我将非常感谢您理解为什么会这样,以及我是否可以采取任何措施来确保我的代码在两个安装上运行.
Ana*_*mar 16
此错误表示您可能已使用变量名定义了一个集set,如果这样做,则会覆盖该built-in函数set.
发生此问题的示例 -
>>> set = set([1,2,3,4,5])
>>> my_set = set([2,3,4,5,6])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'set' object is not callable
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19928 次 |
| 最近记录: |