I'm trying to append inner class instances into a list which is defined as an attribute of the outer class instances. However I get an "AttributeError: type object 'Outer' has no attribute 'Inner_list'". Here's the code:
import matplotlib.pyplot as plt
import numpy as np
#Create new outer class
class Outer():
def __init__(self, name = "", n_users = 1):
self.user_name = name
self.num_users = n_users
self.Inner_list = []
#Create new inner class
class Inner():
def __init__(self, n = 1, P = 0, w = 1, t = 0):
self.number = n
self.power = P
self.num_windows = w
self.func_time = t
def windows(self, w1 = np.array([0,0]), w2 = np.array([0,0])):
self.window_1 = w1
self.window_2 = w2
self.daily_hours = np.zeros(1440)
self.daily_hours[w1[0]:(w1[1])]=np.ones(np.diff(w1))
self.daily_hours[w2[0]:(w2[1])]=np.ones(np.diff(w2))
Outer.Inner_list.append(self)
#Create new instance of outer class
Out_instance_1 = Outer("outer",300)
#Create new instance of inner class
Inn_instance_1 = Out_instance_1.Inner(5,7,2,5)
Inn_instance_1.windows([6*60,8*60],[18*60,23*60])
Python says that Outer object has no attribute "Inner_list", and that's true because I understand that "Inner_list" is an attribute of Outer instances and not of the Outer object. If i create an Outer_instance and type "Outer_instance.App_list" it shows an empty list, as I want. So the problem here is that I am not able to make the code append the Inner instances to the generic Outer instance within which it is defined. Any help will be much appreciated, thanks