NEWBIE: What's the instance name?

Eduardo Elgueta eelgueta at navix.cl
Tue Jan 27 17:30:05 EST 2004


Michael and the rest,

Your analogy is very good. I think of C++ as an enigmatic and
temperamental cat, and I think of Python as last generation language.
I mean, it's ok if in C/C++ you can't get an instance name (another
reason not to use it). But why not in Python? (I use it a lot)

An object can have many references to it? Ok, give me the name of the
instance I'm using to refer to it:

  x.__instance_name__ --> "x"
  foo.__instance_name__ --> "foo"

Or the first it finds, if it's not obvious:

  self.__instance_name__ --> whatever it finds first
  (I'll be carful not to referentiate the instance twice, I promise)

I've never ran into a software design/engineering book saying "storing
an instance name is forbidden under penalty of death."

I don't want to flame anyone. It's just I'm so lazy I wanted to save
myself a parameter in my html generation class, using the instance
name as the html object name:

  python:
    pass = Input(...)
    :
    pass.render(page_buffer)

  html:
    :
    <input type="whatever" name="pass" ...>
    :

Oh well!

Regards,

Ed.

Michael Hudson <mwh at python.net> wrote in message news:<m3y8svrac3.fsf at pc150.maths.bris.ac.uk>...
> engsolnom at ipns.com writes:
> 
> > What I'd like to do is display is the instance name. Is it hiding
> > somewhere?
> 
> 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, in answer to the question "How can I
>       get the name of a variable from C++ when I have the PyObject*?"
> 
> One of my favourite Python quotes...
> 
> Cheers,
> mwh



More information about the Python-list mailing list