I have a class Neuron in one file by python:
class Neuron:
def __init__():
......
def other function():
......
def __repr__(self, level=0):
gap = '\t'*level
_printable = "{}position {} -- map dimensions {} -- input dataset {} element(s) -- level {} \n".format(
gap,
self.position,
self.__weight_map[0].shape,
self.input_dataset.shape[0],
level
)
if self.child_map is not None:
for neuron in self.child_map.neurons.values():
_printable += neuron.__repr__(level+1)
return _printable
When I run main function in other file, it calls this class and return the result like that:
> position (0, 0) -- map dimensions (1, 1, 61) -- input dataset 219 element(s) -- level 0
> position (0, 0) -- map dimensions (2, 4, 61) -- input dataset 28 element(s) -- level 1
> position (0, 0) -- map dimensions (2, 4, 61) -- input dataset 0 element(s) -- level 2
> position (1, 0) -- map dimensions (2, 4, 61) -- input dataset 10 element(s) -- level 2
> position (0, 1) -- map dimensions (2, 4, 61) -- input dataset 4 element(s) -- level 2
> ...
Now I want to calculate how many lines in the result, that's to say, in my opinion, how many times the code use this __repr__
function.
I tried to add a var, like cnt_num_times = 0
, in __repr__
function, and cnt_num_times += 1, however, it still print lots of 1 in the end, so how to correct it?