Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
賢明なる Pythonista の諸兄に於かれましては、どちらの書き方をなさいますでしょうか。
# -*- coding: utf-8 -*-
def class_extender(cls):
def __init__(self, value):
self.value = value
cls.__init__ = __init__
return cls
@class_extender
class Hoge:
def compute(self):
return self.value * 2
if __name__ == '__main__':
hoge = Hoge(3)
print(hoge.compute()) #=> 6
# -*- coding: utf-8 -*-
class HogeBase:
def __init__(self, value):
self.value = value
class Hoge(HogeBase):
def __init__(self, value):
super(self.__class__, self).__init__(value)
def compute(self):
return self.value * 2
if __name__ == '__main__':
hoge = Hoge(3)
print(hoge.compute()) #=> 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.