Skip to content
Advertisement

How to pass variable to base class

Consider the following Python code (Python 3):

  • I have a class Signal comprising all the functions signals of all different kinds should be able to perform.
  • For each kind of signal, I create a new class, where the data is “sampled”, meaning an array with signal data is specified.

If I now want to plot the signal, the plot method of the super() class is called. However, in order to plot the data, the Signal class must somehow access it. Now my question is: What is the cleanest way to pass the signal data to the Signal class?

I have the feeling that there must be a better way than the super().write_data(self.sample()) approach.

JavaScript

Advertisement

Answer

Well, since Harmonics is “based” on Signal, you can acces the attributes defined in Signal. You can simply write:

JavaScript

So, instead of

JavaScript

you write only

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement