我有3个来自同一基类(Progression.py)的子类(例如算术Progression.py,sc2.py,sc3.py)。
在每个子类模块中,我将首先导入基类,以便可以从中继承。例如,假设我正在使用算术Progression.py,那么前几行可能看起来像这样……
from progression import Progression
class ArithmeticProgression(Progression): # Inherit from the Progression Class
""" This is an iterator that produces an arithmetic progression """
现在在主基类中,我想在主代码块的末尾运行以下单元测试,但是我导入了算术Progression.py模块,以便可以运行测试:
from arithmeticProgression import ArithmeticProgression
[CODE BLOCK]
[CODE BLOCK]
[CODE BLOCK]
if __name__ == '__main__':
print('Default progression:')
Progression().print_progression(10)
print('Arithmetic progression with increment 5:')
ArithmeticProgression(5).print_progression(10)
但是,当我运行此代码时,出现以下错误消息:
Traceback (most recent call last):
File "C:/Users/djgra/PycharmProjects/DSAA_Chapter2/progression.py", line 1, in <module>
from arithmeticProgression import ArithmeticProgression
File "C:\Users\djgra\PycharmProjects\DSAA_Chapter2\arithmeticProgression.py", line 1, in <module>
from progression import Progression
File "C:\Users\djgra\PycharmProjects\DSAA_Chapter2\progression.py", line 1, in <module>
from arithmeticProgression import ArithmeticProgression
ImportError: cannot import name 'ArithmeticProgression'
我感觉好像在导入模块中做一些循环操作是导致错误的原因。我在这里的理解中是否缺少从父类和导入语句继承的内容?