Last active
October 20, 2021 08:34
-
-
Save shkumagai/e500666e584c4ea500ee6664a70308f4 to your computer and use it in GitHub Desktop.
override __init__ method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
from __future__ import print_function, unicode_literals | |
class Hoge(object): | |
_foo = None | |
_bar = None | |
_buz = None | |
def __init__(self, foo=1, bar=2, buz="3"): | |
self._foo = foo | |
self._bar = bar | |
self._buz = buz | |
def __str__(self): | |
return "{foo} | {bar} | {buz}".format( | |
foo=self._foo, | |
bar=self._bar, | |
buz=self._buz, | |
) | |
class Fuga(Hoge): | |
_zoo = None | |
def __init__(self, zoo=None, *args, **kwargs): | |
super(Fuga, self).__init__(*args, **kwargs) | |
if zoo is not None and isinstance(zoo, int): | |
self._zoo = zoo | |
def __str__(self): | |
return "{foo} | {bar} | {buz} | {zoo}".format( | |
foo=self._foo, | |
bar=self._bar, | |
buz=self._buz, | |
zoo=self._zoo, | |
) | |
if __name__ == "__main__": | |
h = Hoge() | |
print(h) # noqa: T001 | |
f = Fuga() | |
print(f) # noqa: T001 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment