object query assigned variable name?
Scott David Daniels
Scott.Daniels at Acm.Org
Fri May 1 12:40:13 EDT 2009
warpcat wrote:
> I've passed this around some other groups, and I'm being told
> "probably not possible". But I thought I'd try here as well :) ...
> Given an object:
> class Spam(object):
> def __init__(self):
> # stuff....
> 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.
Here's an example of why it is impossibly hard. What would you want the
following code to print?:
print 'NoneUnique:', Spam() is Spam()
Objects are created and then used somehow (including being put
somewhere), not created int a "variable."
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list