I'm trying to print out the instance name of a class. In this example it's a timer that prints out how long various overlapping sections of my code are running:
class timerstart:
def __init__(self):
# Sets some variables with system time
def stop(self):
# Calculates current total time
print(*instance name*, 'total time is ...')
So when I call it in my code it would look something like:
allcode=timerstart()
# some code
subcode=timerstart()
# some code
subcode.stop()
# some code
allcode.stop()
Which would output:
subcode total time...
allcode total time...
I know I can initialize the function with it's name: allcode=timerstart(name='allcode')
which is annoying.
I am also running into issues with traceback using: inspect.currentframe().f_back.f_locals.items()
Is there a way to print the instance name, like print(self.selfname)
or something?