擅长:python、mysql、java
<p>问题是<code>frank.pet</code>是<code>Pets</code>的<code>list</code>。要做你想做的事,你必须重新定义<code>petsyay</code>来处理宠物列表,并返回一个名字列表</p>
<pre><code>def petsyay(self):
return [p.callpet() for p in self.pet]
</code></pre>
<p>如果您想同时处理两个宠物列表或一个宠物列表,您可以处理异常</p>
<pre><code>def petsyay(self):
try:
return self.pet.callpet()
except AtributeError: #Just handle the AttributeError to prevent hiding another exception
return [p.callpet() for p in self.pet]
</code></pre>