I want to create two classes (Spectrogram and TimeWindow) which should recall one another, but I'm not sure about my definitions. I first define Spectrogram and then TimeWindow afterwards. The logic when using the objects is the following:
- The
window = TimeWindow()object is created - I have a method which creates a
spect = Spectrogram()object, and sets it as attribute ofwindow - I set the
windowobject as attribute of thespectobject, because I want to be able to get one from the other.
First question
The code seems to work. Is this architecture ok? Is there a cleaner way to achieve the fact that I can access one object from the other?
Second question
I tried to define the Spectrogram class as follows, imposing that the input variable time_window is of type TimeWindow. This results in an error, because I define the TimeWindow class after the Spectrogram class. Is there any way to impose the type of time_window?
class Spectrogram:
def __init__(self, time_window:TimeWindow, ...):
self.time_window = time_window
...
Thank you everyone!
time_window: "TimeWindow". You can also dofrom __future__ import annotationsat the top of your file