擅长:python、mysql、java
<p>正如其他人所说,函数在绑定之前被修饰过,所以您不能直接确定它是“方法”还是“函数”。在</p>
<p>判断函数是否为方法的合理方法是检查“self”是否是第一个参数。虽然不是万无一失,但大多数Python代码都遵循以下约定:</p>
<pre><code>import inspect
ismethod = inspect.getargspec(method).args[0] == 'self'
</code></pre>
<hr/>
<p>这里有一个复杂的方法,似乎可以自动地判断出方法是否是一个边界。适用于cpython2.6上的一些简单案例,但没有承诺。如果函数的第一个参数是绑定了修饰函数的对象,则它决定函数是方法。在</p>
^{pr2}$