擅长:python、mysql、java
<p>这是python2.x中<a href="http://docs.python.org/2/reference/datamodel.html#new-style-and-classic-classes" rel="nofollow">new-style and classic classes</a>之间的区别之一。事实上:</p>
<blockquote>
<p>The concept of (old-style) class is unrelated to the concept of type: if <code>x</code> is an instance of an old-style class, <strong>then <code>x.__class__</code> designates the class of <code>x</code>, but <code>type(x)</code> is always <code><type 'instance'></code></strong>.</p>
</blockquote>
<p>您必须使用新的样式类,通过从<code>object</code>继承来获得预期的<code>type()</code>结果。你知道吗</p>
<pre><code>>>> class C1: pass
...
>>> class C2(object): pass
...
>>> type(C1())
<type 'instance'>
>>> type(C2())
<class '__main__.C2'>
</code></pre>