LoginSignup
3
2

More than 5 years have passed since last update.

Python3で、他階層にあるクラスを継承する方法

Posted at

図つきは個人ブログに載せました。

sample.pyからほか階層にあるCore.pyを継承したChildren.pyに定義されているhelloメソッドを呼び出したい。

sample.py

# -*- coding: utf-8 -*-

from business.Children import Children

c = Children()

c.hello()

Core.py

# -*- coding: utf-8 -*-


class Core:
    def __init__(self):
        print('hello core')

Children.py

# -*- coding: utf-8 -*-

from business import Core


class Children(Core.Core):
    def __init__(self):
        pass

    def hello(self):
        print('children hello')
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2