在python中一个子类只能有一个父类吗_在Python中,子类可以与父类在不同的文件中吗?...

我目前有一个父抽象类,它有许多继承自它的子类。基本结构如下:import sqlite3

import os

from abc import ABCMeta, abstractmethod

class ParentClass(object):

"""DOCSTRING"""

__metaclass__ = ABCMeta

def __init__(self, base_path, state_name):

... other methods etc

class ChildClass1(ParentClass):

def __init__(self, base_path):

"""DOCSTRING"""

state_name = 'chromosome'

super().__init__(base_path, state_name)

...other methods etc

class ChildClass2(ParentClass):

def __init__(self, base_path):

"""DOCSTRING"""

state_name = 'ftszRing'

super().__init__(base_path, state_name)

...other methods etc

...other child classes that all inherit from the abstract parent class.

对我来说,将这些代码拆分为文件更有意义:

家长_类.py

儿童1级.py

child_类2.py

child_类3.py

等等

我可以这样做,只需将父类导入到子类中,但是拥有父模块是没有意义的。父类是抽象的,拥有父类的实例没有意义。另外,我喜欢事物当前被继承的方式,导入父类似乎会改变这一点。在

本质上,是否可以像上面那样将代码拆分为文件,而不必对代码进行重大更改?我唯一能弄明白如何做到这一点的方法是在每个文件中都有父类,但这似乎并不“正确”。。。。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值