我有一个包含列表的类。我真的很喜欢它,如果我能够轻松获得我添加到该列表中的顶级对象/类的数量。
class Layer:
class Neuron:
netValue = 0.
activationValue = 0.
weights = []
weightsAfterErrorSubtracted = []
incomingError = 0.
def __init__(self, numberOfWeights):
self.weights = random.random(int(numberOfWeights))
neurons = []
def __init__(self, numberOfNeurons, numberOfWeightsPerNeuron):
for neuron in range(0, numberOfNeurons):
self.neurons.append(self.Neuron(numberOfWeightsPerNeuron))
layer = Layer(40, 200)
print("The length of my list is: " + str(len(layer.neurons)))
问题是,当我在添加神经元后打印出列表的长度时,它包括神经元中所有权重以及该长度,而不仅仅是神经元对象的数量。有没有办法轻松获得列表中的顶级对象数量,而不是他们的孩子?