Skip to content

Instantly share code, notes, and snippets.

@shkumagai
Last active October 20, 2021 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shkumagai/e500666e584c4ea500ee6664a70308f4 to your computer and use it in GitHub Desktop.
Save shkumagai/e500666e584c4ea500ee6664a70308f4 to your computer and use it in GitHub Desktop.
override __init__ method
# 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