擅长:python、mysql、java
<p>在python中,类是第一类对象。您可以像其他任何对象一样将它们指定给变量。<code>channelClass = ClientChannel</code>意味着给<code>BoxesServer.channelClass</code>分配类<code>ClientChannel</code>(作为一个类变量),后面的<code>BoxesServer.channelClass</code>可以像<code>ClientChannel</code>一样使用。你知道吗</p>
<p>如果您从<code>BoxesServer</code>派生,然后在派生类中为<code>channelClass</code>分配另一个类,这可能很有用,这意味着您可以自定义要用来代替<code>ClientChannel</code>的类。例如,您可以在方法中写入:</p>
<pre><code>def getChannelInstance(self, *args, **kwds):
return self.channelClass(*args, **kwds)
</code></pre>
<p>…它将根据类返回一个适当的实例。你知道吗</p>