A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/076527.html below:

Method to give name of class instance?

Method to give name of class instance? Method to give name of class instance?Daniel Klein danielk at aracnet.com
Sun Apr 29 21:11:12 EDT 2001
On Mon, 30 Apr 2001 00:22:53 GMT, timothyr at timothyr.com (Timothy L. Robertson)
wrote:

>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?

If you want it to have a name, you're going to have to give it one yourself...

class MyClass:
    def __init__(self, myname):
        self.myname = myname

>>>classinstance=MyClass('classinstance')
>>>classinstance.myname()
>>>'classinstance'

Daniel Klein
Portland, OR USA

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4