By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,767 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,767 IT Pros & Developers. It's quick & easy.

know reference name in instance

P: n/a
Hello:

Is it possible for an instance know its name used by other part of
program. I mean like this:

class test:
def __init__(self):
pass

when some one writes

x = test()

then one of attribute of x contain the name "x"

Is it possible?

I expect someone can tell me how to do it.

Jul 7 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
pipehappy wrote:
Is it possible for an instance know its name used by other part of
program. I mean like this:

class test:
def __init__(self):
pass

when some one writes

x = test()

then one of attribute of x contain the name "x"

Is it possible?
not really.

and what should happen if you do, say

x = test()
y = x

or

x = [test(), test(), test()]

?

for more on this, see:

http://pyfaq.infogami.com/how-can-my...e-of-an-object

</F>

Jul 7 '06 #2

P: n/a

Fredrik Lundh wrote:
pipehappy wrote:
Is it possible for an instance know its name used by other part of
program. I mean like this:

class test:
def __init__(self):
pass

when some one writes

x = test()

then one of attribute of x contain the name "x"

Is it possible?

not really.

and what should happen if you do, say

x = test()
y = x
I may choose the name when the class is initialized, other may choose
the newest name. It depends.
or

x = [test(), test(), test()]

?
None may be the good answer here.
>
for more on this, see:

http://pyfaq.infogami.com/how-can-my...e-of-an-object

</F>
Yes, You are right. But variety of condition is not necessary
prohibiting the promotion of such question but provides the possibility
for different answer. So is there some way I can ask the environment to
tell me the name?

With respect, I read your words and it's great.

Jul 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.