Method to give name of class instance?
Ben Hutchings
ben.hutchings at roundpoint.com
Sun Apr 29 21:44:53 EDT 2001
timothyr at timothyr.com (Timothy L. Robertson) writes:
> Hi Everyone,
>
> I've been enjoying learning Python very much, but have hit a little
> snag. I want a way to find out the name of a class instance from a
> method. eg.
>
> >>>classinstance=MyClass()
> >>>classinstance.myname()
> 'classinstance'
>
> Is there a way to do this?
No, instances don't have names because they may have any number
of names bound to them, even none at all.
Example 1:
a = MyClass()
b = a
Here, both a and b refer to the same instance.
Example 2:
a = [MyClass()]
Here, no name refers to the instance.
--
Any opinions expressed are my own and not necessarily those of Roundpoint.
More information about the Python-list
mailing list