Skip to content

Instantly share code, notes, and snippets.

@teitei-tk
Created February 20, 2014 01:45
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 teitei-tk/9105486 to your computer and use it in GitHub Desktop.
Save teitei-tk/9105486 to your computer and use it in GitHub Desktop.
class methodの継承で一瞬迷ったのでおさらい。
#!/usr/bin/env python
class Hoge(object):
def run(self):
print "run as Hoge"
def second_run(self):
print "run as Hoge"
class Foo(Hoge):
def run(self):
print "run as Foo"
class Bar(Hoge):
pass
def run():
hoge = Hoge()
foo = Foo()
bar = Bar()
hoge.run() # run as Hoge
hoge.second_run() # run as Hoge
foo.run() # run as Foo
bar.run() # run as Hoge
if __name__ == "__main__":
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment