I'm sorry, name of instance inside its methods

Daniel T. danielt3 at gte.net
Mon Feb 28 08:24:55 EST 2000


In article <Pine.LNX.4.10.10002271841170.10858-100000 at penguin.tamucc.edu>,
adrian lee vega <alv50855 at sci.tamucc.edu> wrote:

>actually you're correct, I want the name of the instance
>not the name of the class
>
>> 
>> >             def classname(self):
>> >                     <blank>
>> > 
>> > -------------------------------
>> > 
>> > >>>from hello import *
>> > >>>clown = Hello(1)
>> > >>>clown.classname()
>> > clown
>> 
>> 
>> hmmm.... looking at that again, "clown" is an instance name, not the
>> name of the class.. which do you actually want?

class Hello:
   def __init__( self, name ):
      self.__name = name
   def instanceName( self ):
      return self.__name

clown = Hello( "clown" )
print clown.instanceName()

Will something like that work?

-- 
When a thing ceases to be a subject of controversy,
it ceases to be a subject of interest.
                                                   -- William Hazlitt



More information about the Python-list mailing list