[英]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 base
, x
, y
, z
和Base
可用作base.x
, base.y
, base.z
和base.Base
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.