Nov-20-2017, 03:05 AM
when I create an instance of a class,
I'm thinking that the new object is somewhere on the call stack,
during the instantiating process. Is it possible to access that name without actually passing it
as part of the init process.
For example in the following routine, I want to extract the value
Bob:
I'm thinking that the new object is somewhere on the call stack,
during the instantiating process. Is it possible to access that name without actually passing it
as part of the init process.
For example in the following routine, I want to extract the value
Bob:
class MyClass(object): def __init__(self, starting_index=0): ''' Initialization :param starting_index: optional initial starting index ''' self.current_index = starting_index # The following gives me the name of self, this class print(self.__class__.__name__) # How can I get the name of an instantiating object (Bob) here? def testit(): Bob = MyClass() if __name__ == '__main__': testit()