object1 is just an identifier (or variable) pointing to an instance object, objects have no names.
>>> class A: ... def foo(self): ... print self ... >>> a = A() >>> b = a >>> c = b >>> a,b,c
a , b , c are just links that allow us to access the same object, when the object has 0 , it automatically collects garbage.
A quick hack would be to pass the name when creating the instance:
>>> class A: ... def __init__(self, name): ... self.name = name ... >>> a = A('a') >>> a.name 'a' >>> foo = A('foo') >>> foo.name 'foo' >>> bar = foo
source share