gae アプリ 開発メモ

Google App Engine アプリの開発メモ / 言語: python, javascript / ビギナー

Pythonで継承元のメソッドを呼び出すには

伝統的な書き方

どんなメソッドを読んでいるのかが明示的。

class C(B):
    def method(self, arg):
        B.method(self, arg)

super() を使用する

なんか便利らしい。
要勉強。

class C(B):
    def method(self, arg):
        super(C, self).method(arg)

一時的なクラスオブジェクトを使用する

super() の代替方法。
メリットは継承元の指定を一定に書けるけど、それがよい事かはまた別の話。

base = B
class C(base):
    def method(self, arg):
        base.method(self, arg)
base = None