くだすれPython(超初心者用) その12at TECHくだすれPython(超初心者用) その12 - 暇つぶし2ch■コピペモード□スレを通常表示□オプションモード□このスレッドのURL■項目テキスト50:デフォルトの名無しさん 11/11/26 06:13:59.61 >>> class Foo1(object): ... def __init__(self): ... pass ... def whoami(self): ... print self.__class__ ... def whoismyparent(self): ... super(self.__class__, self).whoami() ... >>> class Foo2(Foo1): ... def __init__(self): ... super(self.__class__, self).__init__() ... >>> f1 = Foo1() >>> f2 = Foo2() >>> f1.whoami() <class '__main__.Foo1'> >>> f2.whoami() <class '__main__.Foo2'> >>> f1.whoismyparent() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 7, in whoismyparent AttributeError: 'super' object has no attribute 'whoami' >>> f2.whoismyparent() <class '__main__.Foo2'> 51:デフォルトの名無しさん 11/11/26 06:22:33.37 >>> class Foo1(object): ... def __init__(self): ... pass ... def whoami(self): ... print self.__class__ ... def whoismyparent(self): ... print super(self.__class__, self).__class__ ... >>> class Foo2(Foo1): ... def __init__(self): ... super(self.__class__, self).__init__() ... >>> f1 = Foo1() >>> f2 = Foo2() >>> f1.whoami() <class '__main__.Foo1'> >>> f2.whoami() <class '__main__.Foo2'> >>> f1.whoismyparent() <type 'super'> >>> f2.whoismyparent() <type 'super'> 次ページ最新レス表示レスジャンプ類似スレ一覧スレッドの検索話題のニュースおまかせリストオプションしおりを挟むスレッドに書込スレッドの一覧暇つぶし2ch