Python以Java的方式分类

2024-10-02 14:30:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要编写一个结构如下的Python包:

ElectricalSolver {DIR}
      bus.py
      line.py #contains the class lineInterface
      ...
      Solver1 {DIR}
         line.py #(specific implementation of lineInterface for the solver 1, contains the line class)

我希望每个文件有一个类,我希望在调用import时直接导入该类,如下所示:

import ElectricalSolver.Solver1.line

相反,现在我要做的是:

from ElectricalSolver.Solver1.line import line

如何指示通过类的包含文件名加载类?(如爪哇语)

这是一个好的python实践吗?你知道吗


Tags: ofthepyimportdirline结构implementation