function get_class_name()

Michael Hudson mwh at python.net
Fri Mar 14 11:45:46 CET 2003


username <username at ilt.fhg.de> writes:

> Hi,
> 
> I need something (<<code>>) for a class i.e.
> 
> class Hello:
> 	.
> 	.
> 	def get_class_name(self):
> 		<<code>>
> 
> that does this
> 
> >>>World=Hello()
> >>>World.get_class_name()
>    "World"

>From http://www.amk.ca/quotations/python-quotes/page-8.html:

    The same way as you get the name of that cat you found on your
    porch: the cat (object) itself cannot tell you its name, and it
    doesn't really care -- so the only way to find out what it's
    called is to ask all your neighbours (namespaces) if it's their
    cat (object)...

    ....and don't be surprised if you'll find that it's known by many
    names, or no name at all!
                                          -- Fredrik Lundh, 3 Nov 2000

i.e. you don't do that.

Cheers,
M.

-- 
  Arrrrgh, the braindamage!  It's not unlike the massively
  non-brilliant decision to use the period in abbreviations
  as well as a sentence terminator.  Had these people no
  imagination at _all_?                 -- Erik Naggum, comp.lang.lisp




More information about the Python-list mailing list