Extracting name strings from assigned objects

S

Shannon Mayne

I would like to ask how one might obtain the assigned name of an
assigned object as a string. I would like to use object names as an
algorithmic input.


To demonstrate... So if i have:

what can I do to the object 'foo' so as to return the string 'foo'?

Thanks!
 
S

Steven D'Aprano

I would like to ask how one might obtain the assigned name of an
assigned object as a string. I would like to use object names as an
algorithmic input.


To demonstrate... So if i have:


what can I do to the object 'foo' so as to return the string 'foo'?

There's a lot of confusion there. The object 'foo' is a string, and it
doesn't occur anywhere in your code. The name foo is not an object, it is
a name. Perhaps you meant the object {} (an empty dict)?

The object {} doesn't know what names (note plural) it has been bound
too. It could be bound to one name:

foo = {}

or many names:

foo = bar = baz = flib = {}

or no names at all:

{}


Names are not properties of objects. You can't do what you are trying to
do. If you tell us why you want to do this, perhaps we can suggest a way
to do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top