instance name

Irmen de Jong irmen.NOSPAM at xs4all.nl
Sat Apr 2 10:59:04 EST 2005


max(01)* wrote:
> hi.
> 
> is there a way to define a class method which prints the instance name?
> 
> e.g.:
> 
>>>> class class_1:
> ...   def myName(self):
> ...     ????what should i do here????
> ...
>>>> instance_1 = class_1()
>>>> instance_1.myName()
> 'instance_1'
>>>>
> 
> bye
> 
> macs

What should the following do, you think?

>>> a=class_1()
>>> b=a
>>> b is a
True
>>> b.myName()
????print what????

There is no such thing as "the" instance name.
(a and b both point to the same instance, in my example)

Also: why do you want this? It smells like you're
actually looking for the use of a dict to do your job.

--Irmen



More information about the Python-list mailing list