How to get an object's name as a string?

Steve Holden steve at
Wed Oct 29 01:58:59 CET 2008

Steven D'Aprano wrote:
> On Tue, 28 Oct 2008 09:15:50 -0600, Joe Strout wrote:
>> On Oct 28, 2008, at 8:41 AM, Shannon Mayne wrote:
>>> I would like to create objects with algorithmically determined names
>>> based on other object names and use object names for general algorithm
>>> input.
>> What do you mean by the "name" of an object?  Objects don't generally
>> have names, unless you explicitly define a .name property and assign
>> them names.
>> (Variables have names, of course, but a variable isn't an object -- it's
>> just a reference to an object.  Many variables may refer to the same
>> object, so it doesn't make any sense to ask for the name of THE variable
>> which may be referring to an object at the moment.)
> That explanation makes no sense. Given the assignment:
> x = 57
> if the name of x isn't 'x', then what on earth can it possibly mean to 
> ask for the name of a variable?
He didn't ask for the name of a variable, he asked for the name of an
object. You may choose to equate them, but they aren't the same thing.

> In languages like Python, the term "variable" is misleading and 
> confusing. Python's programming model has objects (values), and names. 
> Best to use language that describes what Python actually does, rather 
> than use language that describes what other languages do.
Objects in Python *don't* have names. Period. In Python we don't
normally talk about variables anyway, except when speaking loosely, we
talk about binding names. But please don't let this start another round
of "Python programmers don't know how to describe the language". You
have already made your opinions on that score more than clear.

l = []
del l

What's the name of the list formerly known as "l"?

Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC    

More information about the Python-list mailing list