擅长:python、mysql、java
<p>如果你不想用它,你还有其他选择。传统的鸭子打字解决方案:</p>
<pre><code>try:
clickedblock_place = clickedblock.place
except AttributeError:
# don't place block
else:
clickedblock_place()
</code></pre>
<p>也可以使用hasattr:</p>
^{pr2}$
<p>我几乎从不使用isinstance,除了检查(还是关闭?)例如,如果需要知道名称是指向str还是unicode:</p>
<pre><code>if isinstance(str1, basestring):
blah, blah, blah
</code></pre>
<p>祝你好运,
迈克</p>