Skip to content

Instantly share code, notes, and snippets.

@Gab-km
Created September 30, 2013 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Gab-km/6758226 to your computer and use it in GitHub Desktop.
Save Gab-km/6758226 to your computer and use it in GitHub Desktop.
賢明なる 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