我意识到某些方法应该使用()
调用,而其他方法则不能。我如何通过IPython等工具检查是否需要使用括号?例如下面的文件scratch.py
import numpy as np
arr = np.random.randn(5)
print arr.sort, "\n"
print arr.sort(), "\n";
print arr.shape, "\n";
print arr.shape(), "\n";
生成以下输出:
<built-in method sort of numpy.ndarray object at 0x7fb4b5312300>
None
(5,)
Traceback (most recent call last):
File "scratch.py", line 8, in <module>
print arr.shape(), "\n";
TypeError: 'tuple' object is not callable