假設我有一個名爲Animal的類和一個名爲Dog的子類。我如何從Dog類訪問動物的定義unicode?Python中的父__unicode__
class Animal:
def __unicode__(self):
return 'animal'
class Dog(Animal):
def __unicode__(self):
return 'this %s is a dog' % (I want to get the Animal's __unicode__ here)
這是Python 2還是Python 3? (順便說一下,你的代碼缺少一些'def'關鍵字。) – 2013-02-18 09:56:55
這是python 2.對,對於def的抱歉。 – 2013-02-18 09:57:32