object query assigned variable name?

AKEric warpcat at sbcglobal.net
Fri May 1 13:08:55 EDT 2009


On May 1, 9:48 am, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Fri, 01 May 2009 09:24:10 -0700, warpcat wrote:
> > I'd like it to print, when instanced, something like this:
>
> >>>> s = Spam()
> > I’m assigned to s!
>
> > But it seems prohibitively hard (based on my web and forum searches) for
> > an object to know what variable name is has been assigned to when
> > created.
>
> Can't be done. Objects don't know what names they are bound to.
>
> Furthermore, your question is based on an invalid assumption. Objects
> aren't necessarily bound to a single name, they can be bound to zero,
> one, or more names.
>
> What name should Spam print in these examples?
>
> alist = [1, 2, Spam(), 4]
> alist.append(Spam())
> x = y = z = Spam()
>
> --
> Steven

And getting back all the pointers is fine with me.  But this sounds
like a dead end, and I was just looking for confirmation of that.
Thanks



More information about the Python-list mailing list