我意识到应该使用()
调用某些方法,而其他方法则不能。如何使用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