object query assigned variable name?
warpcat at sbcglobal.net
Fri May 1 19:08:55 CEST 2009
On May 1, 9:48 am, Steven D'Aprano <st... at REMOVE-THIS-
> 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]
> x = y = z = Spam()
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.
More information about the Python-list