简体   繁体   English

最佳实践基础/子类之间的通用导入

[英]best practice common imports between base/child class

I have import statements in base class: 我在基类中有导入语句:

base.py base.py

import x
import y
import z

Class Base {
   ...
}

child.py child.py

import x
import y
import z

Class Child(Base) {
   ...
}

How can I eliminate the redundancy of import x, y, z between the two classes? 如何消除两个类之间导入x,y,z的冗余?

As far as I know, the best practice is considered to keep all imports explicit. 据我所知,最佳实践被认为是使所有进口商品保持明确。 Just the way they are right now. 就是他们现在的样子。

But, you probably need to import base from child in order to inherit from Base . 但是,您可能需要从child导入base才能从Base继承。 When you import base , x , y , z and Base will be available as base.x , base.y , base.z and base.Base . import basexyzBase可用作base.xbase.ybase.zbase.Base

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM